-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/store data #6
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f857875
Input/Output ruby/json, by creating books.json file
francksefu 85bf40f
Feat: people data store
HFG43 797a579
Add rentals features
francksefu 1e867a4
finish write people in file json
francksefu 44ca0b0
Create module input_output
francksefu 2c240f9
Correct linters errors
francksefu df6e149
Correct linters errors
francksefu ee56b9c
Add exit feature
francksefu 672b532
correct linter error
francksefu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"title":"dd","author":"ee"},{"title":"fra","author":"dses"},{"title":"frsc","author":"sd"},{"title":"fra","author":"cc"},{"title":"Lord of ring","author":"Arthur"},{"title":"King","author":"Franck"},{"title":"Gregoire","author":"Alex"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module DataToHash | ||
def student_from_hash(people_data) | ||
classroom = people_data['classroom'] | ||
type = 'Student' | ||
name = people_data['name'] | ||
age = people_data['age'] | ||
permission = people_data['parent_permission'] | ||
Students.new(classroom, type, age, name, parent_permission: permission) | ||
end | ||
|
||
def teacher_from_hash(people_data) | ||
specialization = people_data['specialization'] | ||
type = 'Teacher' | ||
name = people_data['name'] | ||
age = people_data['age'] | ||
Teacher.new(specialization, type, age, name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module InputOutput | ||
def write_file(taked_book, file_name) | ||
json_file = JSON.generate(taked_book) | ||
File.open(file_name, 'w') | ||
File.write(file_name, json_file) | ||
end | ||
|
||
def read_file_book | ||
return [] unless File.exist?('books.json') | ||
|
||
file_name = 'books.json' | ||
File.open(file_name) | ||
take_data = File.read('books.json') | ||
@taked_book = JSON.parse(take_data) | ||
convert_book | ||
end | ||
|
||
def convert_book | ||
@taked_book.each do |i| | ||
@books.push(Book.new(i['title'], i['author'])) | ||
end | ||
end | ||
# Read peoples | ||
|
||
def read_file_people | ||
return [] unless File.exist?('people.json') | ||
|
||
file_name = 'people.json' | ||
File.open(file_name) | ||
take_data = File.read('people.json') | ||
@taked_people = JSON.parse(take_data) | ||
convert_people | ||
end | ||
|
||
def convert_people | ||
@taked_people.each do |i| | ||
if i['type'] == 'Teacher' | ||
@people.push(Teacher.new(i['specialization'], i['type'], i['age'], i['name'], i['id'])) | ||
else | ||
@people.push(Students.new(i['classroom'], i['type'], i['age'], i['name'], i['id'], | ||
parent_permission: i['parent_permission'])) | ||
end | ||
end | ||
end | ||
|
||
# Read rental in file rentals | ||
def read_file_rental | ||
return [] unless File.exist?('rentals.json') | ||
|
||
file_name = 'rentals.json' | ||
File.open(file_name) | ||
take_data = File.read('rentals.json') | ||
@taked_rental = JSON.parse(take_data) | ||
convert_rental | ||
end | ||
|
||
def convert_rental | ||
@taked_rental.each do |i| | ||
if i['person']['type'] == 'Student' | ||
@rental.push(Rental.new(i['date'], | ||
Students.new(i['person']['classroom'], i['person']['type'], | ||
i['person']['age'], i['person']['name'], | ||
i['person']['id'], i['person']['permission']), | ||
Book.new(i['book']['title'], i['book']['author']))) | ||
else | ||
@rental.push(Rental.new(i['date'], | ||
Teacher.new(i['person']['specialization'], i['person']['type'], | ||
i['person']['age'], i['person']['name'], i['person']['id']), | ||
Book.new(i['book']['title'], i['book']['author']))) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require_relative 'app' | ||
require_relative 'manage_data' | ||
|
||
def options_menu | ||
puts 'Please choose your menu option!' | ||
|
@@ -34,7 +35,10 @@ def main | |
loop do | ||
options_menu | ||
choice = gets.chomp.to_i | ||
exit if choice == 7 | ||
if choice == 7 | ||
app.save_people_data | ||
exit | ||
end | ||
handle_menu_choice(choice, app) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"specialization":"dec","type":"Teacher","age":"24","name":"earl","id":705},{"classroom":"3","type":"Student","age":"34","name":"des","id":778,"parent_permission":true},{"specialization":"des","type":"Teacher","age":"24","name":"frav","id":69},{"classroom":"4","type":"Student","age":"33","name":"dev","id":756,"parent_permission":true}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"date":"2022/1/1","book":{"title":"greg","author":"meme"},"person":{"name":"earl","age":"24","id":705,"type":"Teacher","specialization":"dec"}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruby main.rb
I am getting the error ``require_relative': cannot load such file --what you can do is that please remove
require_relative 'manage_data'` form main.rb.