├── .github └── workflows │ ├── linters.yml │ └── tests.yml ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── app.rb ├── book.rb ├── capitalize.rb ├── classroom.rb ├── decorator.rb ├── logo.png ├── main.rb ├── nameable.rb ├── person.rb ├── rental.rb ├── rubocop.yml ├── student.rb ├── teacher.rb ├── testing.rb └── trimmer.rb /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rubocop: 7 | name: Rubocop 8 | runs-on: ubuntu-22.04 9 | 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-ruby@v1 13 | with: 14 | ruby-version: ">=3.1.x" 15 | - name: Setup Rubocop 16 | run: | 17 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ 18 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml 19 | - name: Rubocop Report 20 | run: rubocop --color 21 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | rspec: 7 | name: RSpec 8 | runs-on: ubuntu-22.04 9 | steps: 10 | - uses: actions/checkout@v3 11 | - uses: actions/setup-ruby@v1 12 | with: 13 | ruby-version: 3.1.x 14 | - name: Setup RSpec 15 | run: | 16 | [ -f Gemfile ] && bundle 17 | gem install --no-document rspec -v '>=3.0, < 4.0' 18 | - name: RSpec Report 19 | run: rspec --force-color --format documentation 20 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # gem "rails" 4 | 5 | gem 'rubocop', '>= 1.0', '< 2.0' 6 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | ast (2.4.2) 5 | base64 (0.1.1) 6 | json (2.6.3) 7 | language_server-protocol (3.17.0.3) 8 | parallel (1.23.0) 9 | parser (3.2.2.3) 10 | ast (~> 2.4.1) 11 | racc 12 | racc (1.7.1) 13 | rainbow (3.1.1) 14 | regexp_parser (2.8.1) 15 | rexml (3.2.6) 16 | rubocop (1.56.2) 17 | base64 (~> 0.1.1) 18 | json (~> 2.3) 19 | language_server-protocol (>= 3.17.0) 20 | parallel (~> 1.10) 21 | parser (>= 3.2.2.3) 22 | rainbow (>= 2.2.2, < 4.0) 23 | regexp_parser (>= 1.8, < 3.0) 24 | rexml (>= 3.2.5, < 4.0) 25 | rubocop-ast (>= 1.28.1, < 2.0) 26 | ruby-progressbar (~> 1.7) 27 | unicode-display_width (>= 2.4.0, < 3.0) 28 | rubocop-ast (1.29.0) 29 | parser (>= 3.2.1.0) 30 | ruby-progressbar (1.13.0) 31 | unicode-display_width (2.4.2) 32 | 33 | PLATFORMS 34 | x86_64-linux 35 | 36 | DEPENDENCIES 37 | rubocop (>= 1.0, < 2.0) 38 | 39 | BUNDLED WITH 40 | 2.4.19 41 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2021, Andres Zamorano Medina 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this project and associated documentation files, to deal in the project without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of this project, and to permit persons to whom the project is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the project. 6 | 7 | THIS PROJECT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THIS PROJECT OR THE USE OR OTHER DEALINGS IN THE PROJECT. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | logo 5 |
6 | 7 |

School library

8 | 9 |
10 | 11 | 12 | 13 | # 📗 Table of Contents 14 | 15 | - [📖 About the Project](#about-project) 16 | - [🛠 Built With](#built-with) 17 | - [Tech Stack](#tech-stack) 18 | - [Key Features](#key-features) 19 | - [🚀 Live Demo](#live-demo) 20 | - [💻 Getting Started](#getting-started) 21 | - [Prerequisites](#prerequisites) 22 | - [Setup](#setup) 23 | - [Install](#install) 24 | - [Usage](#usage) 25 | - [Run tests](#run-tests) 26 | - [Deployment](#deployment) 27 | - [👥 Authors](#authors) 28 | - [🔭 Future Features](#future-features) 29 | - [🤝 Contributing](#contributing) 30 | - [⭐️ Show your support](#support) 31 | - [🙏 Acknowledgements](#acknowledgements) 32 | - [❓ FAQ (OPTIONAL)](#faq) 33 | - [📝 License](#license) 34 | 35 | 36 | 37 | # 📖 [School library] 38 | 39 | **[School library]** This project is about building project to control the books in a library, and consult who borrows books. 40 | 41 | ## 🛠 Built With 42 | 43 | ### Tech Stack 44 | 45 |
46 | Technologies 47 | 50 |
51 | 52 |
53 | Linters 54 | 57 |
58 | 59 | 60 | 61 | ### Key Features 62 | 63 | - **[Work with OOP]** 64 | 65 |

(back to top)

66 | 67 | 76 | 77 | 78 | 79 | ## 💻 Getting Started 80 | 81 | To get a local copy. 82 | 83 | ### Prerequisites 84 | 85 | In order to run this project you need to have Ruby installed, check [this](https://www.ruby-lang.org/en/) documentation in order to know how to install it. 86 | 87 | ### Setup 88 | 89 | Clone this repository to your desired folder: 90 | 91 | sh 92 | cd my-folder 93 | git clone https://github.com/Dachrono/OOP-school-library.git 94 | 95 | ### Install 96 | 97 | You do not need install anything more than ruby 98 | 99 | ### Usage 100 | 101 | To run the project, execute the command `ruby name_file.rb`. Example: you can run testing 102 | 103 | ```sh 104 | ruby testing.rb 105 | ``` 106 | 107 | To check linter use: 108 | 109 | ```sh 110 | rubocop 111 | ``` 112 | 113 | To fix the linter use: 114 | 115 | ```sh 116 | rubocop -a 117 | ``` 118 | 119 | 131 | 132 |

(back to top)

133 | 134 | 135 | 136 | ## 👥 Authors 137 | 138 | 👤 **Andy Zam** 139 | 140 | - GitHub: [Andres Zamorano](https://github.com/Dachrono) 141 | - Twitter: [Andres Zamorano](https://twitter.com/Dachrono) 142 | - LinkedIn: [Andres Zamorano](https://www.linkedin.com/in/andres-zamorano-785b77a1/) 143 | 144 |

(back to top)

145 | 146 | 147 | 148 | ## 🔭 Future Features 149 | 150 | - [1] **[I will go to create functionality]** 151 | 152 |

(back to top)

153 | 154 | ## 🤝 Contributing 155 | 156 | Contributions, issues, and feature requests are welcome! 157 | 158 | Feel free to check the [issues page](https://github.com/Dachrono/OOP-school-library/issues). 159 | 160 |

(back to top)

161 | 162 | 163 | 164 | ## ⭐️ Show your support 165 | 166 | If you like this project please feel free to send me corrections for make it better I would feel glad to read your comments.
167 | And think If you enjoy gift me a star. 168 | 169 |

(back to top)

170 | 171 | 179 | 180 | ## ❓ FAQ (OPTIONAL) 181 | 182 | 183 | - **[Can I use with a templeate your project?]** 184 | 185 | - [Of course I would feel honored] 186 | 187 | - **[Your project is free license?]** 188 | 189 | - [Yeah, you can use it completly] 190 | 191 |

(back to top)

192 | 193 | 194 | 195 | ## 📝 License 196 | 197 | this project is [MIT](./LICENSE.txt) licensed. 198 | 199 |

(back to top)

200 | -------------------------------------------------------------------------------- /app.rb: -------------------------------------------------------------------------------- 1 | require_relative 'student' 2 | require_relative 'classroom' 3 | require_relative 'teacher' 4 | require_relative 'book' 5 | require_relative 'rental' 6 | 7 | # app class 8 | class App 9 | def initialize 10 | @books = [] 11 | @people = [] 12 | @rentals = [] 13 | end 14 | 15 | def list_all_books 16 | puts 'List of books' 17 | 18 | @books.each_with_index do |book, idx| 19 | puts "\n #{idx}) Title: #{book.title} written by: #{book.author}" 20 | end 21 | end 22 | 23 | def list_all_people 24 | puts 'List of people' 25 | 26 | @people.each_with_index do |person, idx| 27 | puts "\n #{idx}) #{person.type} id: (#{person.id}) Name: #{person.name} age: #{person.age}" 28 | end 29 | end 30 | 31 | def add_student(age, name) 32 | puts 'Classroom' 33 | clas = gets.chomp.strip 34 | puts 'Parent permission select Y(yes)/N(no)' 35 | per = gets.chomp.strip 36 | per = per == 'y' 37 | 38 | classroom = Classroom.new(clas) 39 | student = Student.new(classroom, 'Student', age, name, parent_permision: per) 40 | @people << student 41 | puts 'Student created succesfully' 42 | end 43 | 44 | def add_teacher(age, name) 45 | puts 'Specialization' 46 | spec = gets.chomp.strip 47 | 48 | teacher = Teacher.new(spec, 'Teacher', age, name) 49 | @people << teacher 50 | puts 'Teacher created succesfully' 51 | end 52 | 53 | def create_person 54 | puts "Select type of person to register \n Student select 1 - Teacher select 2" 55 | option = gets.chomp.strip.to_i 56 | puts 'Age' 57 | age = gets.chomp.strip.to_i 58 | puts 'Name' 59 | name = gets.chomp.strip 60 | 61 | add_student(age, name) if option == 1 62 | 63 | add_teacher(age, name) if option == 2 64 | end 65 | 66 | def create_book 67 | puts 'Please share me the book data' 68 | 69 | puts 'Title' 70 | title = gets.chomp.strip 71 | 72 | puts 'Author' 73 | author = gets.chomp.strip 74 | 75 | book = Book.new(title, author) 76 | @books << book 77 | 78 | puts 'Book created succesfully' 79 | end 80 | 81 | def select_book 82 | puts 'Select number of book' 83 | list_all_books 84 | gets.chomp.strip.to_i 85 | end 86 | 87 | def select_person 88 | puts 'Select index of this list (DO NOT USE ID)' 89 | list_all_people 90 | gets.chomp.strip.to_i 91 | end 92 | 93 | def enter_date 94 | puts 'Enter date' 95 | gets.chomp.strip 96 | end 97 | 98 | def create_and_register_rental(book, person, date) 99 | book = @books[book] 100 | person = @people[person] 101 | 102 | @rentals << Rental.new(date, book, person) 103 | puts 'Loan registered.' 104 | end 105 | 106 | def create_rental 107 | book = select_book 108 | person = select_person 109 | if person < @people.length && book < @books.length 110 | date = enter_date 111 | create_and_register_rental(book, person, date) 112 | else 113 | puts 'Wrong option!!! You need select a list index value' 114 | end 115 | end 116 | 117 | def all_rentals 118 | puts 'Loans active' 119 | 120 | puts 'Select your user by ID' 121 | list_all_people 122 | id = gets.chomp.strip.to_i 123 | 124 | @rentals.each_with_index do |rental, _idx| 125 | puts "Date: #{rental.date}, Book #{rental.book.title} by #{rental.book.author}" if rental.person.id == id 126 | end 127 | end 128 | end 129 | -------------------------------------------------------------------------------- /book.rb: -------------------------------------------------------------------------------- 1 | require_relative 'rental' 2 | 3 | # book class 4 | class Book 5 | attr_accessor :title, :author, :rentals 6 | 7 | def initialize(title, author) 8 | @title = title 9 | @author = author 10 | @rentals = [] 11 | end 12 | 13 | def rental_new(person, date) 14 | Rental.new(date, self, person) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /capitalize.rb: -------------------------------------------------------------------------------- 1 | require_relative 'decorator' 2 | # capitalize class 3 | class Capitalize < Decorator 4 | def correct_name 5 | @nameable.correct_name.capitalize 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /classroom.rb: -------------------------------------------------------------------------------- 1 | # classroom class 2 | class Classroom 3 | attr_accessor :label 4 | attr_reader :students 5 | 6 | def initialize(label) 7 | @label = label 8 | @students = [] 9 | end 10 | 11 | def add_student(student) 12 | @students << student 13 | student.classroom = self 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /decorator.rb: -------------------------------------------------------------------------------- 1 | require_relative 'nameable' 2 | # decorator class 3 | class Decorator < Nameable 4 | def initialize(nameable) 5 | super() 6 | @nameable = nameable 7 | end 8 | 9 | def correct_name 10 | @nameable.correct_name 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dachrono/OOP-school-library/fd1736ab882ba2cacb3fe182a8795903f1292b28/logo.png -------------------------------------------------------------------------------- /main.rb: -------------------------------------------------------------------------------- 1 | require_relative 'app' 2 | # menu 3 | 4 | def menu 5 | puts 6 | puts 'Select a option: ' 7 | puts '1 - List all books' 8 | puts '2 - List all people' 9 | puts '3 - Create a person' 10 | puts '4 - Create a book' 11 | puts '5 - Create a rental' 12 | puts '6 - List all rentals for a given person id' 13 | puts '7 - Exit' 14 | end 15 | 16 | def switch(call, option) 17 | case option 18 | when 1 then call.list_all_books 19 | when 2 then call.list_all_people 20 | when 3 then call.create_person 21 | when 4 then call.create_book 22 | when 5 then call.create_rental 23 | when 6 then call.all_rentals 24 | else 25 | puts 'Thank you for your visit' 26 | end 27 | end 28 | 29 | def init 30 | call = App.new 31 | puts 'Welcome' 32 | 33 | loop do 34 | menu 35 | option = gets.chomp.strip.to_i 36 | switch(call, option) 37 | break if option < 1 || option > 6 38 | end 39 | end 40 | 41 | init 42 | -------------------------------------------------------------------------------- /nameable.rb: -------------------------------------------------------------------------------- 1 | # nameable class 2 | class Nameable 3 | def correct_name 4 | raise NotImplementedError, 'This method should be overwriten' 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /person.rb: -------------------------------------------------------------------------------- 1 | require_relative 'nameable' 2 | require_relative 'rental' 3 | # Person class 4 | class Person < Nameable 5 | attr_reader :id 6 | attr_accessor :name, :age, :rentals, :type 7 | 8 | def initialize(type, age, name = 'Unknown', parent_permision: true) 9 | super() 10 | @id = Random.rand(1..1000) 11 | @name = name 12 | @age = age 13 | @parent_permision = parent_permision 14 | @rentals = [] 15 | @type = type 16 | end 17 | 18 | def can_use_services? 19 | of_age? || @parent_permision 20 | end 21 | 22 | def correct_name 23 | @name 24 | end 25 | 26 | def add_rental(book, date) 27 | Rental.new(date, book, self) 28 | end 29 | 30 | private 31 | 32 | def of_age? 33 | age >= 18 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /rental.rb: -------------------------------------------------------------------------------- 1 | require_relative 'book' 2 | require_relative 'person' 3 | 4 | # rental class 5 | class Rental 6 | attr_accessor :date, :book, :person 7 | 8 | def initialize(date, book, person) 9 | @date = date 10 | @book = book 11 | @person = person 12 | person.rentals << self 13 | book.rentals << self 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - "Guardfile" 5 | - "Rakefile" 6 | - "node_modules/**/*" 7 | 8 | DisplayCopNames: true 9 | 10 | Layout/LineLength: 11 | Max: 120 12 | Metrics/MethodLength: 13 | Max: 20 14 | Metrics/AbcSize: 15 | Max: 50 16 | Metrics/ClassLength: 17 | Max: 150 18 | Metrics/BlockLength: 19 | IgnoredMethods: ['describe'] 20 | Max: 30 21 | 22 | 23 | Style/Documentation: 24 | Enabled: false 25 | Style/ClassAndModuleChildren: 26 | Enabled: false 27 | Style/EachForSimpleLoop: 28 | Enabled: false 29 | Style/AndOr: 30 | Enabled: false 31 | Style/DefWithParentheses: 32 | Enabled: false 33 | Style/FrozenStringLiteralComment: 34 | EnforcedStyle: never 35 | 36 | Layout/HashAlignment: 37 | EnforcedColonStyle: key 38 | Layout/ExtraSpacing: 39 | AllowForAlignment: false 40 | Layout/MultilineMethodCallIndentation: 41 | Enabled: true 42 | EnforcedStyle: indented 43 | Lint/RaiseException: 44 | Enabled: false 45 | Lint/StructNewOverride: 46 | Enabled: false 47 | Style/HashEachMethods: 48 | Enabled: false 49 | Style/HashTransformKeys: 50 | Enabled: false 51 | Style/HashTransformValues: 52 | Enabled: false 53 | -------------------------------------------------------------------------------- /student.rb: -------------------------------------------------------------------------------- 1 | require_relative 'person' 2 | 3 | # Student class 4 | class Student < Person 5 | attr_reader :classroom 6 | 7 | def initialize(classroom, type, age, name = 'Unknown', parent_permision: true) 8 | super(type, age, name, parent_permision: parent_permision) 9 | @classroom = classroom 10 | end 11 | 12 | def play_hooky 13 | '¯\(ツ)/¯' 14 | end 15 | 16 | def classroom=(classroom) 17 | @classroom = classroom 18 | classroom.students.push(self) unless 19 | classroom.students.include?(self) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /teacher.rb: -------------------------------------------------------------------------------- 1 | require_relative 'person' 2 | 3 | # Teacher class 4 | class Teacher < Person 5 | def initialize(specialization, type, age, name = 'Unknown', parent_permision: true) 6 | super(type, age, name, parent_permision: parent_permision) 7 | @specialization = specialization 8 | end 9 | 10 | def can_use_services? 11 | true 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /testing.rb: -------------------------------------------------------------------------------- 1 | require_relative 'person' 2 | require_relative 'capitalize' 3 | require_relative 'trimmer' 4 | require_relative 'student' 5 | require_relative 'classroom' 6 | require_relative 'book' 7 | require_relative 'rental' 8 | 9 | puts '--!!-- Testing decorate' 10 | 11 | person = Person.new(22, 'maximilianus') 12 | person.correct_name 13 | capitalized_person = Capitalize.new(person) 14 | puts capitalized_person.correct_name 15 | capitalized_trimmed_person = Trimmer.new(capitalized_person) 16 | puts capitalized_trimmed_person.correct_name 17 | puts 18 | 19 | puts '--!!-- Testing relations' 20 | puts '--!!-- Relation class <-> student' 21 | 22 | student1 = Student.new(25, 1, 'Mauricio') 23 | classroom1 = Classroom.new('A101') 24 | 25 | print classroom1.students 26 | print student1.classroom 27 | 28 | classroom1.add_student(student1) 29 | 30 | print classroom1.students 31 | print student1.classroom 32 | puts 33 | puts 34 | 35 | puts '--!!-- Relation book <-> rental' 36 | 37 | book = Book.new('Librito', 'Escritorsito') 38 | 39 | book.rental_new(student1, '01-08-2023') 40 | 41 | print book.rentals 42 | puts 43 | puts 44 | 45 | puts '--!!-- Relation person <-> rental' 46 | 47 | person.add_rental(book, '02-08-2023') 48 | 49 | print person.rentals 50 | puts puts 51 | print book.rentals.count 52 | -------------------------------------------------------------------------------- /trimmer.rb: -------------------------------------------------------------------------------- 1 | require_relative 'decorator' 2 | # trimmer class 3 | class Trimmer < Decorator 4 | def correct_name 5 | original_name = @nameable.correct_name 6 | original_name.length > 10 ? original_name[0, 10] : original_name 7 | end 8 | end 9 | --------------------------------------------------------------------------------