Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
671f34d
Update README.md
OLIPLICHE Nov 15, 2021
fede100
constructor
OLIPLICHE Nov 16, 2021
51424c6
Update person.rb file
OLIPLICHE Nov 16, 2021
9127223
Update teacher file
OLIPLICHE Nov 16, 2021
9bbe8d1
Update student
OLIPLICHE Nov 16, 2021
f3149f4
Update Readme
OLIPLICHE Nov 16, 2021
0630791
update person file
OLIPLICHE Nov 16, 2021
0d3c5cc
set corrector class
OLIPLICHE Nov 17, 2021
5c377ee
Update corrector class
OLIPLICHE Nov 17, 2021
5c38e32
link corrector class to person
OLIPLICHE Nov 17, 2021
90b9361
Add validate Method
OLIPLICHE Nov 17, 2021
676176f
Fix linters erros
OLIPLICHE Nov 17, 2021
5d87c2c
Add Test
OLIPLICHE Nov 17, 2021
ec5cf92
Merge pull request #2 from OLIPLICHE/decorate
OLIPLICHE Nov 17, 2021
05b0170
create a classroom.rb class
OLIPLICHE Nov 18, 2021
11f43f4
create has many relationship
OLIPLICHE Nov 18, 2021
e45971a
Update classroom.rb
OLIPLICHE Nov 18, 2021
0894bd1
Update classroom files
OLIPLICHE Nov 18, 2021
8920916
Update classroom
OLIPLICHE Nov 18, 2021
07dedcd
Fix linters errore
OLIPLICHE Nov 18, 2021
041eddb
Create rental.rb
OLIPLICHE Nov 19, 2021
071224d
create book.rb
OLIPLICHE Nov 19, 2021
5369b45
Update rental.rb
OLIPLICHE Nov 19, 2021
e6940ad
Merge pull request #3 from OLIPLICHE/associations
OLIPLICHE Nov 19, 2021
12129e2
create main.rb file
OLIPLICHE Nov 19, 2021
ab7a620
update main
OLIPLICHE Nov 19, 2021
44ed270
update main
OLIPLICHE Nov 19, 2021
44282d1
Update main
OLIPLICHE Nov 19, 2021
816ff9e
Update main
OLIPLICHE Nov 19, 2021
064356d
update main.rb file
OLIPLICHE Nov 19, 2021
03de907
change parent_permission sintax inside person file
OLIPLICHE Nov 19, 2021
82e263b
change parent_permission sintax inside student file
OLIPLICHE Nov 19, 2021
78e3de0
change parent_permission sintax inside teacher file
OLIPLICHE Nov 19, 2021
b80b5b5
Merge pull request #4 from OLIPLICHE/basic-UI
OLIPLICHE Nov 19, 2021
9ef0c3e
Add linkedIn link
OLIPLICHE Nov 20, 2021
9e7f07d
Update Readme
OLIPLICHE Nov 20, 2021
8703067
add diagram image
OLIPLICHE Nov 20, 2021
06d4727
add images
OLIPLICHE Nov 20, 2021
673d66f
add images
OLIPLICHE Nov 20, 2021
347eb01
Update Readme
OLIPLICHE Nov 20, 2021
dd7e084
Merge pull request #5 from OLIPLICHE/basic-UI
OLIPLICHE Nov 20, 2021
c73538c
Update README.md
OLIPLICHE Nov 23, 2021
f6c431e
Update README.md
OLIPLICHE Nov 23, 2021
8e5fd7d
Update README.md
OLIPLICHE Nov 23, 2021
26ee3f9
Update README.md
OLIPLICHE Nov 23, 2021
225a4d7
Update README.md
OLIPLICHE Nov 23, 2021
09df23d
Update README.md
OLIPLICHE Nov 23, 2021
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
20 changes: 20 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Linters

on: pull_request

jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: ">=3.0.x"
- name: Setup Rubocop
run: |
gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/
[ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml
- name: Rubocop Report
run: rubocop --color
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tests

on: pull_request

jobs:
rspec:
name: RSpec
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: 3.0.x
- name: Setup RSpec
run: |
[ -f Gemfile ] && bundle
gem install --no-document rspec -v '>=3.0, < 4.0'
- name: RSpec Report
run: rspec --force-color --format documentation
52 changes: 52 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
AllCops:
NewCops: enable
Exclude:
- "Guardfile"
- "Rakefile"
- "node_modules/**/*"

DisplayCopNames: true

Layout/LineLength:
Max: 120
Metrics/MethodLength:
Max: 20
Metrics/AbcSize:
Max: 50
Metrics/ClassLength:
Max: 150
Metrics/BlockLength:
IgnoredMethods: ['describe']
Max: 30


Style/Documentation:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/EachForSimpleLoop:
Enabled: false
Style/AndOr:
Enabled: false
Style/DefWithParentheses:
Enabled: false
Style/FrozenStringLiteralComment:
EnforcedStyle: never

Layout/HashAlignment:
EnforcedColonStyle: key
Layout/ExtraSpacing:
AllowForAlignment: false
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
Lint/RaiseException:
Enabled: false
Lint/StructNewOverride:
Enabled: false
Style/HashEachMethods:
Enabled: false
Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'rubocop', '>= 1.0', '< 2.0'
32 changes: 32 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
parallel (1.21.0)
parser (3.0.2.0)
ast (~> 2.4.1)
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
rubocop (1.23.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.12.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.13.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
unicode-display_width (2.1.0)

PLATFORMS
x64-mingw32

DEPENDENCIES
rubocop (>= 1.0, < 2.0)

BUNDLED WITH
2.2.22
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# school-library
## School-library
Imagine that you are the librarian of OOP University, and you need a tool to record what books are in the library and who borrows them. This app that I created will make your library the best organized one.
This app allows you to:
- Add new students or teachers.
- Add new books.
- Save records of who borrowed a given book and when.
![WebImages](./images/p0.JPG)

![WebImages](./images/p1.JPG)
![WebImages](./images/p2.JPG)
![WebImages](./images/p3.JPG)
![WebImages](./images/p4.JPG)
## Built With
- Ruby
- OOP
- rubocop

## Author
👤 **Olipliche Mavoungou Paka**
- GitHub: [https://github.com/OLIPLICHE)
- LinkedIn: [LinkedIn](https://www.linkedin.com/in/olipliche/)

## 🤝 Contributing
Contributions, Issues, and feature requests are welcome!

## Show your support
Give a ⭐️ if you like this project
## Acknowledgments
- Hat tip to anyone whose code was used
- Inspiration

## 📝 License
This project is [Microverse](https://www.microverse.org/) licensed.
15 changes: 15 additions & 0 deletions book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Book
attr_accessor :title, :author
attr_reader :rentals

def initialize(title, author)
@title = title
@author = author
@rentals = []
end

def add_rental(rental)
@rentals << rental
rental.book = self
end
end
14 changes: 14 additions & 0 deletions classroom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Classroom
attr_accessor :label
attr_reader :students

def initialize(label)
@label = label
@students = []
end

def add_student(student)
@students << student
student.classroom = self
end
end
11 changes: 11 additions & 0 deletions corrector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Corrector
def correct_name(name)
get_name = name.strip.capitalize

if get_name.length > 10
get_name[0, 10]
else
get_name
end
end
end
Binary file added images/p0.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/p1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/p2.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/p3.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/p4.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 184 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
require './person'
require './book'
require './classroom'
require './corrector'
require './rental'
require './student'
require './teacher'

class App
attr_accessor :books, :persons, :rentals

def initialize
@books = []
@people = []
@rentals = []
@class = Classroom.new('Grade 7')
end

def run
print 'Welcome to School Library App!'
sleep 0.75
menu
end

def menu
puts
puts 'Please choose on option by entering a number'
puts '1 - List all books'
puts '2 - List all people'
puts '3 - Create a person'
puts '4 - Create a book'
puts '5 - Create a rental'
puts '6 - List all rentals for a given person id'
puts '7 - Exit'
option = gets.chomp

get_option option
end

# rubocop:disable Metrics/CyclomaticComplexity
def get_option(input)
case input
when '1'
list_all_books
when '2'
list_all_people
when '3'
create_a_person
when '4'
create_a_book
when '5'
create_a_rental
when '6'
list_rentals_by_person_id
when '7'
puts 'Thank you for using this app!'
else
puts 'Please enter a number between 1 and 7'
end
end
# rubocop:enable Metrics/CyclomaticComplexity

def list_all_books
puts 'There are no books yet! Kindly add books.' if @books.empty?

@books.each { |book| puts "Title: #{book.title}, Author: #{book.author}" }
sleep 0.75
menu
end

def list_all_people
puts 'There are no people yet! Kindly add a student or teacher.' if @people.empty?
@people.map { |person| puts "[#{person.class}] Name: #{person.name}, ID: #{person.id}, Age: #{person.age}" }
sleep 0.75
menu
end

def create_a_person
print 'Do you want to create a student (1) or teacher (2) [Input a number]: '
option = gets.chomp

case option
when '1'
create_a_student
when '2'
create_a_teacher
else
puts 'Invalid input. Kindly type 1 or 2'
end
end

def create_a_student
print 'Age: '
age = gets.chomp.to_i

print 'Name: '
name = gets.chomp

print 'Has parent permission? [Y/N]: '
parent_permission = gets.chomp.downcase

student = Student.new(age, @class, name, parent_permission)
@people << student

puts 'Student created successfully'
sleep 0.75
menu
end

def create_a_teacher
print 'Age: '
age = gets.chomp.to_i

print 'Name: '
name = gets.chomp

print 'Specialization: '
specialization = gets.chomp

teacher = Teacher.new(specialization, age, name)
@people << teacher

puts 'Teacher created successfully'
sleep 0.75
menu
end

def create_a_book
print 'Title: '
title = gets.chomp

print 'Author: '
author = gets.chomp

book = Book.new(title, author)
@books << book

puts 'Book added successfully'
sleep 0.75
menu
end
end

def create_a_rental
puts 'Select a book from the following list by number'
@books.each_with_index { |book, index| puts "#{index}) Title: #{book.title}, Author: #{book.author}" }

book_id = gets.chomp.to_i

puts 'Select a person from the following list by number (not id)'
@people.each_with_index do |person, index|
puts "#{index}) [#{person.class}] Name: #{person.name}, ID: #{person.id}, Age: #{person.age}"
end

person_id = gets.chomp.to_i

print 'Date: '
date = gets.chomp.to_s

rental = Rental.new(date, @people[person_id], @books[book_id])
@rentals << rental

puts 'Rental created successfully'
sleep 0.75
menu
end

def list_rentals_by_person_id
print 'ID of person: '
id = gets.chomp.to_i

puts 'Rentals:'
@rentals.each do |rental|
puts "Date: #{rental.date}, Book: '#{rental.book.title}' by #{rental.book.author}" if rental.person.id == id
end
sleep 0.75
menu
end

def main
app = App.new
app.run
end
main
Loading