Skip to content
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

OOP school library: preserve data #6

Merged
merged 14 commits into from
May 24, 2023
Prev Previous commit
Next Next commit
Change ids to attribute writer
  • Loading branch information
shafiuyushawu committed May 24, 2023
commit 379e59054a8ae4d2d9d45041f87dd1d03e6e27e9
8 changes: 2 additions & 6 deletions data/books.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[
{
"title": "Grief Child",
"author": "Lawrence Darmani"
},
{
"title": "Ancestral Sacrifice",
"author": "Akosombo Nyantakyi"
"title": "Grief child",
"author": "George"
}
]
25 changes: 16 additions & 9 deletions data/people.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
[
{
"id": 15,
"name": "Nicholas",
"age": "25",
"id": 630,
"name": "Amen",
"age": "20",
"type": "Student",
"parent_permission": true
},
{
"id": 601,
"name": "Shafiu",
"age": "50",
"id": 204,
"name": "Shafu",
"age": "30",
"type": "Teacher",
"specialization": null
},
{
"id": 78,
"name": "Yushawu",
"age": "23",
"id": 163,
"name": "shafiu",
"age": "10 ",
"type": "Student",
"parent_permission": true
},
{
"id": 357,
"name": "Amen",
"age": "20",
"type": "Teacher",
"specialization": "math"
}
]
9 changes: 2 additions & 7 deletions data/rentals.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
[
{
"date": "02-02-21",
"date": "02-02-20",
"people_index": 0,
"book_index": 1
},
{
"date": "02-03-22",
"people_index": 0,
"book_index": 1
"book_index": 0
}
]
2 changes: 2 additions & 0 deletions modules/read_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def read_people
data.each do |person|
if person['type'] == 'Student'
student = Student.new(person['age'], person['name'], person['parent_permission'])
student.id = person['id']
people << student
else
teacher = Teacher.new(person['age'], person['name'], person['parent_permission'])
teacher.id = person['id']
people << teacher
end
end
Expand Down
3 changes: 0 additions & 3 deletions modules/select.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
require_relative '../app'
require_relative 'read_data'
require 'pry'

class Select
def initialize
@app = App.new
@read = ReadData.new
end

def select(option)
case option
when '1'
@read.read_books
@app.list_books
when '2'
@app.list_people
Expand Down
3 changes: 1 addition & 2 deletions modules/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

class Student < Person
attr_reader :classroom, :parent_permission

attr_writer :id
def initialize(age, name, parent_permission, classroom: 'Unknown')
super(age, name)
@id = Random.rand(1...100)
@classroom = classroom
@parent_permission = parent_permission
end
Expand Down
3 changes: 1 addition & 2 deletions modules/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

class Teacher < Person
attr_accessor :specialization

attr_writer :id
def initialize(age, name, specialization)
super(age, name)
@id = Random.rand(1...1000)
@specialization = specialization
end

Expand Down