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

Feature/clean code #5

Merged
merged 9 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- **Use composition**
- **Implement book & rental associations**
- **Built interactive console app**
- **Make sure it use SOLID, YAGNI, KISS, DRY principles**

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand Down Expand Up @@ -94,11 +95,18 @@ To fix the linter use:
- Twitter: [@twitterhandle](https://twitter.com/HFG_43)
- LinkedIn: [LinkedIn](https://www.linkedin.com/in/hern%C3%A1n-g%C3%BCemes-a440591b/)

πŸ‘€ **Franck Sefu**

- GitHub: [francksefu](https://github.com/francksefu)
- Twitter: [francksefu](https://twitter.com/franck_sefu)
- LinkedIn: [francksefu](https://www.linkedin.com/in/franck-sefu/)

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## πŸ”­ Future Features <a name="future-features"></a>

- [ ] **Run tests**
- [ ] **Preserve data**

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand Down
59 changes: 17 additions & 42 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative 'inputs'
require_relative 'book'
require_relative 'student'
require_relative 'classroom'
Expand Down Expand Up @@ -26,90 +27,64 @@ def list_all_people
end

def create_person
print 'Do you want to create a student (1) or a teacher (2)? [Input the number]'
selected_person = gets.chomp.to_i
selected_person = selected_person_input
name = obtain_person_name
age = obtain_person_age

if selected_person == 1
create_a_student
create_a_student(name, age)
elsif selected_person == 2
create_a_teacher
create_a_teacher(name, age)
else
puts 'Option not recognized, please try another one'
create_person
end
end

def create_a_student
def create_a_student(name, age)
type = 'Student'
puts 'Age: '
age = gets.chomp.to_i

puts 'Name: '
name = gets.chomp

puts 'Classroom: '
classroom = gets.chomp
classroom = assign_student_classroom
Classroom.new(classroom)

puts 'Has parent permission? [Y/N]:'
parent_permission = gets.chomp.capitalize
parent_permission = student_has_permission
permission = (parent_permission == 'Y')
@people.push(Students.new(classroom, type, age, name, parent_permission: permission))
puts 'Student was created successfully'
puts "\n"
end

def create_a_teacher
def create_a_teacher(name, age)
type = 'Teacher'
puts 'Specialization: '
specialization = gets.chomp

puts 'Name: '
name = gets.chomp

puts 'Age: '
age = gets.chomp
specialization = obtain_teacher_specialization

@people.push(Teacher.new(specialization, type, age, name))
puts 'Teacher was created successfully'
puts "\n"
end

def create_a_book
puts 'Book title: '
title = gets.chomp
title = obtain_book_title

puts 'Book Author: '
author = gets.chomp
author = obtain_book_author
puts 'Book was created successfully'
puts "\n"

@books.push(Book.new(title, author))
end

def create_a_rental
puts 'Select the book (index) for rent'
puts "\n"
list_all_books
book = gets.chomp.to_i
book = select_book_for_rental
person = select_who_will_rent

puts 'Select the person (index) that will rent the book'
puts "\n"
list_all_people
person = gets.chomp.to_i

puts 'Define the rental date: '
puts "\n"
date = gets.chomp
date = define_rental_date
@rental.push(Rental.new(date, @people[person], @books[book]))
puts 'Rental was created successfully'
puts "\n"
end

def rental_person_id
puts 'Select the person (id) to review its rentals'
list_all_people
id = gets.chomp.strip.to_i
id = select_person_id_for_rentals

@rental.map do |rental|
puts "\n On #{rental.date} rental of #{rental.book.title}, by #{rental.book.author}" if rental.person.id == id
Expand Down
71 changes: 71 additions & 0 deletions inputs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require_relative 'app'

# Methods for creating persons
def selected_person_input
print 'Do you want to create a student (1) or a teacher (2)? [Input the number]'
gets.chomp.to_i
end

def obtain_person_name
puts 'Name of person: '
gets.chomp
end

def obtain_person_age
puts 'Age of person: '
gets.chomp
end

def assign_student_classroom
puts 'student classroom: '
gets.chomp
end

def student_has_permission
puts 'Has parent permission? [Y/N]:'
gets.chomp.capitalize
end

def obtain_teacher_specialization
puts 'Specialization: '
gets.chomp
end

# Methods for creating a book
def obtain_book_title
puts 'Book title: '
gets.chomp
end

def obtain_book_author
puts 'Book Author: '
gets.chomp
end

# Methods for generating a book rental
def select_book_for_rental
puts 'Select the book (index) for rent'
puts "\n"
list_all_books
gets.chomp.to_i
end

def select_who_will_rent
puts 'Select the person (index) that will rent the book'
puts "\n"
list_all_people
gets.chomp.to_i
end

def define_rental_date
puts 'Define the rental date: '
puts "\n"
gets.chomp
end

# Method for getting rentals per person ID
def select_person_id_for_rentals
puts 'Select the person (id) to review its rentals'
list_all_people
gets.chomp.strip.to_i
end
Loading