From 6f3af4c78699aef07610093b805dc5f715d2dcc5 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Mon, 13 Mar 2023 18:04:44 +0100 Subject: [PATCH 01/16] add person, student, and teacher entities --- .github/workflows/linter.yml | 20 ++++++++++ .github/workflows/tree.yml | 19 +++++++++ GemFile | 1 + GemFile.lock | 33 ++++++++++++++++ README.md | 74 ++++++++++++++++++++++++++++++++++++ person.rb | 41 ++++++++++++++++++++ rubocop.yml | 52 +++++++++++++++++++++++++ student.rb | 16 ++++++++ teacher.rb | 17 +++++++++ 9 files changed, 273 insertions(+) create mode 100644 .github/workflows/linter.yml create mode 100644 .github/workflows/tree.yml create mode 100644 GemFile create mode 100644 GemFile.lock create mode 100644 README.md create mode 100644 person.rb create mode 100644 rubocop.yml create mode 100644 student.rb create mode 100644 teacher.rb diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..3b33c28 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,20 @@ +name: Linters + +on: pull_request + +jobs: + rubocop: + name: Rubocop + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-ruby@v1 + with: + ruby-version: ">=3.1.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 \ No newline at end of file diff --git a/.github/workflows/tree.yml b/.github/workflows/tree.yml new file mode 100644 index 0000000..f786456 --- /dev/null +++ b/.github/workflows/tree.yml @@ -0,0 +1,19 @@ +name: Tests + +on: pull_request + +jobs: + rspec: + name: RSpec + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-ruby@v1 + with: + ruby-version: 3.1.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 \ No newline at end of file diff --git a/GemFile b/GemFile new file mode 100644 index 0000000..207f505 --- /dev/null +++ b/GemFile @@ -0,0 +1 @@ +gem 'rubocop', '>= 1.0', '< 2.0' \ No newline at end of file diff --git a/GemFile.lock b/GemFile.lock new file mode 100644 index 0000000..a74bc02 --- /dev/null +++ b/GemFile.lock @@ -0,0 +1,33 @@ +GEM + specs: + ast (2.4.2) + json (2.6.3) + parallel (1.22.1) + parser (3.2.1.1) + ast (~> 2.4.1) + rainbow (3.1.1) + regexp_parser (2.7.0) + rexml (3.2.5) + rubocop (1.48.0) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.26.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.27.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.4.2) + +PLATFORMS + x64-mingw-ucrt + +DEPENDENCIES + rubocop (>= 1.0, < 2.0) + +BUNDLED WITH + 2.3.26 diff --git a/README.md b/README.md new file mode 100644 index 0000000..187aff8 --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +## **Description** +**OOP School Library** Aims to create a simple library management system for a school using Ruby programming language. The system should allow librarians to add books to the library, track books that are checked out by students, and manage student accounts. + +## **Prerequisites:** +- Basic Knowledge of [Ruby](https://www.educative.io/blog/intro-to-ruby-tutorial) Programming Language +- Basic Knowledge of [Git](https://www.freecodecamp.org/news/git-and-github-for-beginners/) Command + +- Watch [video](https://www.youtube.com/watch?v=RGOj5yH7evk) to get started in Git + + +## **Build With:** + +- [Ruby](https://www.educative.io/blog/intro-to-ruby-tutorial) + +## **INSTALLATION** + +To install the application, follow these steps: + +- Install Ruby 2.7 or later on your system. You can download it from the official Ruby website: https://www.ruby-lang.org/en/downloads/ + +- Clone this repository using Git: +```bash +git clone https://github.com/Ridwanullahi-code/OOP-School-Library.git +``` +
OR
+ +```bash +git clone git@github.com:Ridwanullahi-code/OOP-School-Library.git +``` +- Navigate to the project directory: +```bash + cd OOP-School-Library +``` +- Install the required gems: +```bash + bundle install +``` +## **USAGE** +To run the application, follow these steps: +- Navigate to the project directory: +```bash + cd OOP-School-Library +``` +- Run the application: +```bash + ruby main.rb +``` +- Follow the on-screen prompts to use the application. + +## **Show your support** + +Give a ⭐️ if you like this project! + +## **Authors** + +- Github: [Ridwan](https://github.com/Ridwanullahi-code) +- LinkedIn: [Ridwan](https://www.linkedin.com/in/ajayi-ridwan/) + +## 🚀 **About Me** + +I'm full stack software developer, Computer science, and Microverse student. + +**Stack:** Python, JavaScript, Bootstrap, Ruby, Rails, React, Redux. Available for hire! +## 🤝 **Contributing** +If you would like to contribute to this project, please fork the repository, make your changes, and submit a pull request. Please make sure to follow the coding style and write tests for your changes. + +Feel free to check the [issues page](https://github.com/Ridwanullahi-code/OOP-School-Library/issues/) +## **Acknowledgements** + +- [Microverse](https://www.microverse.org/) + +## **License** + +This project is [MIT](https://choosealicense.com/licenses/mit/LICENSE) licensed. diff --git a/person.rb b/person.rb new file mode 100644 index 0000000..c7f3770 --- /dev/null +++ b/person.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# person class store person information and properties +class Person + attr_accessor :name, :age + attr_reader :id + + def initialize(age, name = 'Unknown', parent_permission: true) + @id = generate_id + @age = age + @name = name + @parent_permission = parent_permission + end + + def display_info + { 'id' => @id, 'name' => @name, 'age' => @age } + end + + def update_info(name, age) + @name = name + @age = age + end + + def can_use_services + if of_age || @parent_permission + true + elsif !of_age || !@parent_permission + false + end + end + + private + + def of_age + @age.to_i >= 18 + end + + def generate_id + rand(1..100) + end +end diff --git a/rubocop.yml b/rubocop.yml new file mode 100644 index 0000000..4948d48 --- /dev/null +++ b/rubocop.yml @@ -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 \ No newline at end of file diff --git a/student.rb b/student.rb new file mode 100644 index 0000000..50a6fde --- /dev/null +++ b/student.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative('./person') +# student class store student information and properties +class Student < Person + attr_accessor :classroom + + def initialize(classroom) + @classroom = classroom + super(age, name, parent_permission: true) + end + + def play_hook + "¯\(ツ)/¯" + end +end diff --git a/teacher.rb b/teacher.rb new file mode 100644 index 0000000..b2a204c --- /dev/null +++ b/teacher.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require_relative('./person') +# class to store teacher information and methods +class Teacher < Person + attr_accessor :specialization + + def initialize(age, name, specialization, parent_permission: false) + @specialization = specialization + super(age, name, parent_permission: parent_permission) + end + + def can_use_services + (of_age || !of_age) || (@parent_permission || !@parent_permission) + end +end + From 0df90d92b83f963c17f7590bd5a9843316def029 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Mon, 13 Mar 2023 18:08:17 +0100 Subject: [PATCH 02/16] correct linter error --- teacher.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/teacher.rb b/teacher.rb index b2a204c..93edc2f 100644 --- a/teacher.rb +++ b/teacher.rb @@ -14,4 +14,3 @@ def can_use_services (of_age || !of_age) || (@parent_permission || !@parent_permission) end end - From c4b4baf84f0d60aae831eebea8ed9b7d9fdc565b Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Mon, 13 Mar 2023 18:22:44 +0100 Subject: [PATCH 03/16] correct linter error --- rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.yml b/rubocop.yml index 4948d48..2e6c2bc 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -1,4 +1,4 @@ -AllCops: +`AllCops: NewCops: enable Exclude: - "Guardfile" From d44a3c1e1e78f8cddbda5819bbfe90961fd01991 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Mon, 13 Mar 2023 18:25:31 +0100 Subject: [PATCH 04/16] correct linter error --- rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.yml b/rubocop.yml index 2e6c2bc..4948d48 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -1,4 +1,4 @@ -`AllCops: +AllCops: NewCops: enable Exclude: - "Guardfile" From 0496b321620be3d10460cebdf8ab5258a2991cd9 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 08:19:23 +0100 Subject: [PATCH 05/16] correct linter error --- rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubocop.yml b/rubocop.yml index 4948d48..508a3a9 100644 --- a/rubocop.yml +++ b/rubocop.yml @@ -16,7 +16,7 @@ Metrics/AbcSize: Metrics/ClassLength: Max: 150 Metrics/BlockLength: - IgnoredMethods: ['describe'] + AllowedMethods: ['describe'] Max: 30 From e70a51b972337c8e21f42998fd6e7abfdfc4fbf0 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 08:32:47 +0100 Subject: [PATCH 06/16] correct linter error --- .github/workflows/{linter.yml => linters.yml} | 0 .github/workflows/{tree.yml => tests.yml} | 0 rubocop.yml => .rubocop.yml | 0 GemFile | 3 ++- GemFile.lock | 1 + person.rb | 2 -- student.rb | 4 +--- teacher.rb | 2 -- 8 files changed, 4 insertions(+), 8 deletions(-) rename .github/workflows/{linter.yml => linters.yml} (100%) rename .github/workflows/{tree.yml => tests.yml} (100%) rename rubocop.yml => .rubocop.yml (100%) diff --git a/.github/workflows/linter.yml b/.github/workflows/linters.yml similarity index 100% rename from .github/workflows/linter.yml rename to .github/workflows/linters.yml diff --git a/.github/workflows/tree.yml b/.github/workflows/tests.yml similarity index 100% rename from .github/workflows/tree.yml rename to .github/workflows/tests.yml diff --git a/rubocop.yml b/.rubocop.yml similarity index 100% rename from rubocop.yml rename to .rubocop.yml diff --git a/GemFile b/GemFile index 207f505..64f6df6 100644 --- a/GemFile +++ b/GemFile @@ -1 +1,2 @@ -gem 'rubocop', '>= 1.0', '< 2.0' \ No newline at end of file +source "https://rubygems.org" +gem 'rubocop', '>= 1.0', '< 2.0' diff --git a/GemFile.lock b/GemFile.lock index a74bc02..40454d9 100644 --- a/GemFile.lock +++ b/GemFile.lock @@ -1,4 +1,5 @@ GEM + remote: https://rubygems.org/ specs: ast (2.4.2) json (2.6.3) diff --git a/person.rb b/person.rb index c7f3770..aba9a17 100644 --- a/person.rb +++ b/person.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # person class store person information and properties class Person attr_accessor :name, :age diff --git a/student.rb b/student.rb index 50a6fde..ecd32f1 100644 --- a/student.rb +++ b/student.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require_relative('./person') # student class store student information and properties class Student < Person @@ -11,6 +9,6 @@ def initialize(classroom) end def play_hook - "¯\(ツ)/¯" + '¯(ツ)/¯' end end diff --git a/teacher.rb b/teacher.rb index 93edc2f..2ed30df 100644 --- a/teacher.rb +++ b/teacher.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require_relative('./person') # class to store teacher information and methods class Teacher < Person From e13858308dc8dea8bd5bdd1f8f63166c34c90f8a Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 09:44:45 +0100 Subject: [PATCH 07/16] update readme file --- README.md | 123 +++++++++++++++++++++++++++++++++++++++++++++------- nameable.rb | 4 ++ 2 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 nameable.rb diff --git a/README.md b/README.md index 187aff8..a210534 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,62 @@ -## **Description** + + +# 📗 Table of Contents + +- [📖 About the Project](#about-project) + - [🛠 Built With](#built-with) + - [Tech Stack](#tech-stack) + - [Key Features](#key-features) + - [🚀 Live Demo](#live-demo) +- [💻 Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Setup](#setup) + - [Install](#install) + - [Usage](#usage) + - [Run tests](#run-tests) + - [Deployment](#triangular_flag_on_post-deployment) +- [👥 Authors](#authors) +- [🔭 Future Features](#future-features) +- [🤝 Contributing](#contributing) +- [⭐️ Show your support](#support) +- [📝 License](#license) + + + +# 📖 OOP School Library + **OOP School Library** Aims to create a simple library management system for a school using Ruby programming language. The system should allow librarians to add books to the library, track books that are checked out by students, and manage student accounts. +## 🛠 Built With + +### Tech Stack + +
+ Client + +
+ + + +### Key Features + +- **Decodes morse code into human readable format** + +

(back to top)

+ + + +## 💻 Getting Started + +To get a local copy up and running, follow these steps. + +### Prerequisites + +In order to run this project you need: + ## **Prerequisites:** - Basic Knowledge of [Ruby](https://www.educative.io/blog/intro-to-ruby-tutorial) Programming Language - Basic Knowledge of [Git](https://www.freecodecamp.org/news/git-and-github-for-beginners/) Command @@ -8,10 +64,14 @@ - Watch [video](https://www.youtube.com/watch?v=RGOj5yH7evk) to get started in Git -## **Build With:** + -- [Ruby](https://www.educative.io/blog/intro-to-ruby-tutorial) - ## **INSTALLATION** To install the application, follow these steps: @@ -47,28 +107,59 @@ To run the application, follow these steps: ``` - Follow the on-screen prompts to use the application. -## **Show your support** + + +## 👥 Authors + +👤 **Ajayi Ridwan** -Give a ⭐️ if you like this project! +- GitHub: [@Ridwanullahi-code](https://github.com/Ridwanullahi-code) +- Twitter: [@Ridwanullahi22](https://twitter.com/twitterhandle) +- LinkedIn: [LinkedIn](https://www.linkedin.com/in/ajayi-ridwan/) -## **Authors** +

(back to top)

-- Github: [Ridwan](https://github.com/Ridwanullahi-code) -- LinkedIn: [Ridwan](https://www.linkedin.com/in/ajayi-ridwan/) + + +## 🤝 Contributing +If you would like to contribute to this project, please fork the repository, make your changes, and submit a pull request. Please make sure to follow the coding style and write tests for your changes. +Feel free to check the [issues page](https://github.com/Ridwanullahi-code/OOP-School-Library/issues/) ## 🚀 **About Me** I'm full stack software developer, Computer science, and Microverse student. **Stack:** Python, JavaScript, Bootstrap, Ruby, Rails, React, Redux. Available for hire! -## 🤝 **Contributing** -If you would like to contribute to this project, please fork the repository, make your changes, and submit a pull request. Please make sure to follow the coding style and write tests for your changes. -Feel free to check the [issues page](https://github.com/Ridwanullahi-code/OOP-School-Library/issues/) -## **Acknowledgements** +

(back to top)

+ + + +## ⭐️ Show your support + +If you like this project... + +Feel free to give it a start + +

(back to top)

+ + + +## 🙏 Acknowledgments + +> Give credit to everyone who inspired your codebase. +> Thanks Microverse for providing us with the right material to aid this project development + +

(back to top)

+ +

(back to top)

+ + + +## 📝 License -- [Microverse](https://www.microverse.org/) +This project is [MIT](./LICENSE) licensed. -## **License** +_NOTE: we recommend using the [MIT license](https://choosealicense.com/licenses/mit/) - you can set it up quickly by [using templates available on GitHub](https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/adding-a-license-to-a-repository). You can also use [any other license](https://choosealicense.com/licenses/) if you wish._ -This project is [MIT](https://choosealicense.com/licenses/mit/LICENSE) licensed. +

(back to top)

\ No newline at end of file diff --git a/nameable.rb b/nameable.rb new file mode 100644 index 0000000..e3e1dfd --- /dev/null +++ b/nameable.rb @@ -0,0 +1,4 @@ +class Nameable + + +end \ No newline at end of file From 85866fb424a5d8173a441c72ef5257a5dd8785a1 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 09:48:13 +0100 Subject: [PATCH 08/16] update readme file --- nameable.rb | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 nameable.rb diff --git a/nameable.rb b/nameable.rb deleted file mode 100644 index e3e1dfd..0000000 --- a/nameable.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Nameable - - -end \ No newline at end of file From 3dd1e9359ca37c908d92d9e5953cc6bbfa605d0f Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 10:23:18 +0100 Subject: [PATCH 09/16] complete decorator --- base_decorator.rb | 11 +++++++++++ capitalize_decorator.rb | 8 ++++++++ nameable.rb | 5 +++++ person.rb | 8 ++++++-- trimmer_decorator.rb | 14 ++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 base_decorator.rb create mode 100644 capitalize_decorator.rb create mode 100644 nameable.rb create mode 100644 trimmer_decorator.rb diff --git a/base_decorator.rb b/base_decorator.rb new file mode 100644 index 0000000..2b50411 --- /dev/null +++ b/base_decorator.rb @@ -0,0 +1,11 @@ +require_relative('./nameable.rb') + +class BaseDecorator < Nameable + def initialize(nameable) + super() + @nameable = nameable + end + def correct_name + @nameable.correct_name + end +end \ No newline at end of file diff --git a/capitalize_decorator.rb b/capitalize_decorator.rb new file mode 100644 index 0000000..7af92ff --- /dev/null +++ b/capitalize_decorator.rb @@ -0,0 +1,8 @@ +require_relative('./base_decorator.rb') +require_relative('./person.rb') + +class CapitalizeDecorator < BaseDecorator + def correct_name + @nameable.correct_name.capitalize + end +end \ No newline at end of file diff --git a/nameable.rb b/nameable.rb new file mode 100644 index 0000000..05baa49 --- /dev/null +++ b/nameable.rb @@ -0,0 +1,5 @@ +class Nameable + def correct_name + raise NotImplementedError, "Class must implemented" + end +end \ No newline at end of file diff --git a/person.rb b/person.rb index aba9a17..cc591ca 100644 --- a/person.rb +++ b/person.rb @@ -1,5 +1,6 @@ +require_relative('./nameable.rb') # person class store person information and properties -class Person +class Person < Nameable attr_accessor :name, :age attr_reader :id @@ -26,7 +27,10 @@ def can_use_services false end end - + + def correct_name + @name + end private def of_age diff --git a/trimmer_decorator.rb b/trimmer_decorator.rb new file mode 100644 index 0000000..a5456de --- /dev/null +++ b/trimmer_decorator.rb @@ -0,0 +1,14 @@ +require_relative('./base_decorator') +require_relative('./person') +require_relative('./capitalize_decorator') + +class TrimmerDecorator < BaseDecorator + def correct_name + name = @nameable.correct_name + if name.length > 10 + name.slice(0, 10) + else + name + end + end +end \ No newline at end of file From 77f0fbc44addcf94c0db0d2a5c0ec5f2fe365bd0 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 10:29:22 +0100 Subject: [PATCH 10/16] complete decorator --- base_decorator.rb | 19 ++++++++++--------- capitalize_decorator.rb | 12 ++++++------ nameable.rb | 8 ++++---- person.rb | 6 ++++-- trimmer_decorator.rb | 2 +- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/base_decorator.rb b/base_decorator.rb index 2b50411..dffb7ef 100644 --- a/base_decorator.rb +++ b/base_decorator.rb @@ -1,11 +1,12 @@ -require_relative('./nameable.rb') +require_relative('./nameable') class BaseDecorator < Nameable - def initialize(nameable) - super() - @nameable = nameable - end - def correct_name - @nameable.correct_name - end -end \ No newline at end of file + def initialize(nameable) + super() + @nameable = nameable + end + + def correct_name + @nameable.correct_name + end +end diff --git a/capitalize_decorator.rb b/capitalize_decorator.rb index 7af92ff..1f5242d 100644 --- a/capitalize_decorator.rb +++ b/capitalize_decorator.rb @@ -1,8 +1,8 @@ -require_relative('./base_decorator.rb') -require_relative('./person.rb') +require_relative('./base_decorator') +require_relative('./person') class CapitalizeDecorator < BaseDecorator - def correct_name - @nameable.correct_name.capitalize - end -end \ No newline at end of file + def correct_name + @nameable.correct_name.capitalize + end +end diff --git a/nameable.rb b/nameable.rb index 05baa49..92bebdb 100644 --- a/nameable.rb +++ b/nameable.rb @@ -1,5 +1,5 @@ class Nameable - def correct_name - raise NotImplementedError, "Class must implemented" - end -end \ No newline at end of file + def correct_name + raise NotImplementedError, 'Class must implemented' + end +end diff --git a/person.rb b/person.rb index cc591ca..638a515 100644 --- a/person.rb +++ b/person.rb @@ -1,10 +1,11 @@ -require_relative('./nameable.rb') +require_relative('./nameable') # person class store person information and properties class Person < Nameable attr_accessor :name, :age attr_reader :id def initialize(age, name = 'Unknown', parent_permission: true) + super() @id = generate_id @age = age @name = name @@ -27,10 +28,11 @@ def can_use_services false end end - + def correct_name @name end + private def of_age diff --git a/trimmer_decorator.rb b/trimmer_decorator.rb index a5456de..76360a5 100644 --- a/trimmer_decorator.rb +++ b/trimmer_decorator.rb @@ -11,4 +11,4 @@ def correct_name name end end -end \ No newline at end of file +end From 0cdc0bfed243f201679832b3c9550df12aefeb0b Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 14:18:29 +0100 Subject: [PATCH 11/16] implement associations --- book.rb | 15 +++++++++++++++ classroom.rb | 16 ++++++++++++++++ person.rb | 8 +++++++- rental.rb | 12 ++++++++++++ student.rb | 9 +++++++-- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 book.rb create mode 100644 classroom.rb create mode 100644 rental.rb diff --git a/book.rb b/book.rb new file mode 100644 index 0000000..cc84dcf --- /dev/null +++ b/book.rb @@ -0,0 +1,15 @@ +require_relative('./rental') +class Book + attr_accessor :title, :author, :rental + + def initialize(title, author) + @title = title + @author = author + @rentals = [] + end + + def add_rental(date, person) + rental = Rental.new(date, self, person) + rentals << rental + end +end diff --git a/classroom.rb b/classroom.rb new file mode 100644 index 0000000..cc3cb0e --- /dev/null +++ b/classroom.rb @@ -0,0 +1,16 @@ +require_relative './student' + +class Classroom + attr_accessor :label, :students + + def initialize(label) + @label = label + @students = [] + end + + def add_student(student) + # saving each student object in an array + @students << student + student.classroom = self + end +end diff --git a/person.rb b/person.rb index 638a515..f6b70f2 100644 --- a/person.rb +++ b/person.rb @@ -1,7 +1,7 @@ require_relative('./nameable') # person class store person information and properties class Person < Nameable - attr_accessor :name, :age + attr_accessor :name, :age, :rentals attr_reader :id def initialize(age, name = 'Unknown', parent_permission: true) @@ -10,6 +10,7 @@ def initialize(age, name = 'Unknown', parent_permission: true) @age = age @name = name @parent_permission = parent_permission + @rentals = [] end def display_info @@ -33,6 +34,11 @@ def correct_name @name end + def add_rental(date, book) + rental = Rental.new(date, book, self) + @rentals << rental + end + private def of_age diff --git a/rental.rb b/rental.rb new file mode 100644 index 0000000..3289de4 --- /dev/null +++ b/rental.rb @@ -0,0 +1,12 @@ +require_relative('./book') +require_relative('./person') + +class Rental + attr_accessor :date, :book, :person + + def initialize(date, _book, _person) + @date = date + @book.rental << self + @person.rentals << self + end +end diff --git a/student.rb b/student.rb index ecd32f1..1fad937 100644 --- a/student.rb +++ b/student.rb @@ -1,14 +1,19 @@ require_relative('./person') +require_relative('./classroom') # student class store student information and properties class Student < Person attr_accessor :classroom - def initialize(classroom) + def initialize(age, classroom, name = 'Unknown', parent_permission: true) @classroom = classroom - super(age, name, parent_permission: true) + super(age, name, parent_permission: parent_permission) end def play_hook '¯(ツ)/¯' end + + def add_classroom + @classroom.add_students(self) + end end From 736e85ea8c0abb00bbcd5bdb006ea197eb89aad0 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 15:15:18 +0100 Subject: [PATCH 12/16] make changes base on code review request --- book.rb | 7 +------ classroom.rb | 3 +++ person.rb | 5 ----- rental.rb | 1 + 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/book.rb b/book.rb index cc84dcf..202c17f 100644 --- a/book.rb +++ b/book.rb @@ -1,15 +1,10 @@ require_relative('./rental') class Book - attr_accessor :title, :author, :rental + attr_accessor :title, :author, :rentals def initialize(title, author) @title = title @author = author @rentals = [] end - - def add_rental(date, person) - rental = Rental.new(date, self, person) - rentals << rental - end end diff --git a/classroom.rb b/classroom.rb index cc3cb0e..cf11a45 100644 --- a/classroom.rb +++ b/classroom.rb @@ -14,3 +14,6 @@ def add_student(student) student.classroom = self end end + +s = Student.new('Micheal', '30', 'LT2') +puts s diff --git a/person.rb b/person.rb index f6b70f2..e668705 100644 --- a/person.rb +++ b/person.rb @@ -34,11 +34,6 @@ def correct_name @name end - def add_rental(date, book) - rental = Rental.new(date, book, self) - @rentals << rental - end - private def of_age diff --git a/rental.rb b/rental.rb index 3289de4..7184ede 100644 --- a/rental.rb +++ b/rental.rb @@ -1,5 +1,6 @@ require_relative('./book') require_relative('./person') +require_relative('./student') class Rental attr_accessor :date, :book, :person From 854476d598439ccab463f8cfe0d99b741c39358c Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Tue, 14 Mar 2023 16:04:56 +0100 Subject: [PATCH 13/16] make second change --- book.rb | 3 +-- person.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/book.rb b/book.rb index cc84dcf..a828698 100644 --- a/book.rb +++ b/book.rb @@ -9,7 +9,6 @@ def initialize(title, author) end def add_rental(date, person) - rental = Rental.new(date, self, person) - rentals << rental + Rental.new(date, self, person) end end diff --git a/person.rb b/person.rb index f6b70f2..918bcff 100644 --- a/person.rb +++ b/person.rb @@ -35,8 +35,7 @@ def correct_name end def add_rental(date, book) - rental = Rental.new(date, book, self) - @rentals << rental + Rental.new(date, book, self) end private From 558461efe3e6014934e59f8763b5452f2c303452 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Wed, 15 Mar 2023 00:20:47 +0100 Subject: [PATCH 14/16] complete ui design --- app.rb | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++ book.rb | 7 +-- main.rb | 42 ++++++++++++++++++ rental.rb | 6 ++- student.rb | 2 +- teacher.rb | 2 +- 6 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 app.rb create mode 100644 main.rb diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..2275328 --- /dev/null +++ b/app.rb @@ -0,0 +1,126 @@ +require_relative('./person') +require_relative('./book') +require_relative('./student') +require_relative('./teacher') +require_relative('./rental') + +class App + def initialize + @books = [] + @people = [] + @rentals = [] + end + + def all_books + if @books.empty? + puts 'No books in the library yet' + else + @books.each do |book| + puts "Title: #{book.title} Author: #{book.author}" + end + end + end + + def all_people + if @people.empty? + puts 'No people in the library yet' + else + @people.each do |person| + puts "class: #{person.class} ID: #{person.id} Name: #{person.name} Age: #{person.age}" + end + end + end + + def create_person + print 'Do you want to create a Teacher (1) or teacher (2)? [input number]: ' + type = gets.chomp.to_i + case type + when 1 + create_student + when 2 + create_teacher + else + puts 'Invalid input. Try again' + end + end + + def create_student + print('Enter Student Age: ') + age = gets.chomp.to_i + print('Enter Student Name: ') + name = gets.chomp + print('Has parent permission? [Y/N]') + permission = gets.chomp.to_s.downcase == 'y' + @people << Student.new(age, name, parent_permission: permission) + puts 'Person created successfully' + end + + def create_teacher + print('Enter Teacher Age: ') + age = gets.chomp.to_i + print('Enter Teacher Name: ') + name = gets.chomp + print 'Enter Teacher Specialization: ' + special = gets.chomp + @people << Teacher.new(age, name, specialization: special) + puts 'Person created successfully' + end + + def create_book + print 'Enter the title of the book: ' + title = gets.chomp + print 'Enter author of the book: ' + author = gets.chomp + @books << Book.new(title, author) + puts 'Book created successfully' + end + + def create_rental + if @books.empty? || @people.empty? + puts "\e[31mNo books or people in the library yet.\e[0m" + return + end + book = select_book + person = select_person + if person && book + print 'Date: ' + date = gets.chomp.to_s + @rentals << Rental.new(date, book, person) + puts 'Rental created successfully.' + else + puts "\e[31mInvalid person or book selected. Please try again.\e[0m" + end + end + + def select_book + puts 'Select a book from the following list by number ' + @books.each_with_index do |book, index| + puts "\e[34m#{index + 1}. Title: \"#{book.title}\", Author: #{book.author} \e[0m" + end + book_idx = gets.chomp.to_i - 1 + @books[book_idx] + end + + def select_person + puts 'Select a person from the following list by number (not id) ' + @people.each_with_index do |person, index| + puts "\e[34m#{index + 1}. [#{person.class}] Name: #{person.name}, ID: #{person.id}, Age: #{person.age} \e[0m" + end + person_idx = gets.chomp.to_i - 1 + @people[person_idx] + end + + def all_rentals_for_person + print 'ID of person: ' + person_id = gets.chomp.to_i + rentals = @rentals.select { |r| r.person.id.to_i == person_id } + if rentals.empty? + puts "\e[31mNo rentals found for this person. Please try again.\e[0m" + else + puts 'Rentals: ' + rentals.each do |rental| + puts "\e[34mDate: #{rental.date}, Book: \"#{rental.book.title}\" by #{rental.book.author}\e[0m" + end + end + end +end diff --git a/book.rb b/book.rb index cc84dcf..202c17f 100644 --- a/book.rb +++ b/book.rb @@ -1,15 +1,10 @@ require_relative('./rental') class Book - attr_accessor :title, :author, :rental + attr_accessor :title, :author, :rentals def initialize(title, author) @title = title @author = author @rentals = [] end - - def add_rental(date, person) - rental = Rental.new(date, self, person) - rentals << rental - end end diff --git a/main.rb b/main.rb new file mode 100644 index 0000000..817f41e --- /dev/null +++ b/main.rb @@ -0,0 +1,42 @@ +require_relative './app' +def main + app = App.new + loop do + puts "\n\e[32mPlease choose an option by entering a number: \e[0m" + 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' + input = gets.chomp.to_i + exit_app if input == 7 + run(app, input) + end +end + +def run(app, input) + @options = { + 1 => app.method(:all_books), + 2 => app.method(:all_people), + 3 => app.method(:create_person), + 4 => app.method(:create_book), + 5 => app.method(:create_rental), + 6 => app.method(:all_rentals_for_person) + } + option = @options[input] + if option + option.call + else + puts "\e[31mInvalid option. Try again.\e[0m" + end +end + +def exit_app + puts "\e[32mThank you for using this app!\e[0m" + sleep(1) + exit +end + +main diff --git a/rental.rb b/rental.rb index 3289de4..325b486 100644 --- a/rental.rb +++ b/rental.rb @@ -4,9 +4,11 @@ class Rental attr_accessor :date, :book, :person - def initialize(date, _book, _person) + def initialize(date, book, person) @date = date - @book.rental << self + @book = book + @person = person + @book.rentals << self @person.rentals << self end end diff --git a/student.rb b/student.rb index 1fad937..0cac085 100644 --- a/student.rb +++ b/student.rb @@ -4,7 +4,7 @@ class Student < Person attr_accessor :classroom - def initialize(age, classroom, name = 'Unknown', parent_permission: true) + def initialize(age, name = 'Unknown', parent_permission: true, classroom: nil) @classroom = classroom super(age, name, parent_permission: parent_permission) end diff --git a/teacher.rb b/teacher.rb index 2ed30df..9f52213 100644 --- a/teacher.rb +++ b/teacher.rb @@ -3,7 +3,7 @@ class Teacher < Person attr_accessor :specialization - def initialize(age, name, specialization, parent_permission: false) + def initialize(age, name, parent_permission: false, specialization: nil) @specialization = specialization super(age, name, parent_permission: parent_permission) end From 88cc95972534e173d1db93a33e5dfcac4a710fef Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Wed, 15 Mar 2023 00:47:03 +0100 Subject: [PATCH 15/16] update readme file --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a210534..6ca46d2 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ # 📖 OOP School Library -**OOP School Library** Aims to create a simple library management system for a school using Ruby programming language. The system should allow librarians to add books to the library, track books that are checked out by students, and manage student accounts. +**OOP School Library** Is a Ruby OOP application that helps manage a library's collection of books, rentals, students, teachers, and borrowing transactions. The project aims to provide an efficient and user-friendly interface for librarians to add, and search for books, as well as manage borrower accounts and track borrowing transactions. ## 🛠 Built With @@ -43,10 +43,14 @@ ### Key Features -- **Decodes morse code into human readable format** +- **Book class:** This class represents each book in the library, with attributes such as title, author. +- **Rentals class:** This class represents library rentals, with attributes such as type of person, name, contact information, and borrowing history + +- **App class:** This class serves as the main interface for librarians, providing methods to add, shows all books, and search for books with specified id , as well as manage borrower accounts and track borrowing transactions

(back to top)

+**The project utilize various OOP principles, such as encapsulation, inheritance,polymorphism, Abstraction, associations, and decomposition to ensure a well-organized and easy-to-maintain codebase.** ## 💻 Getting Started From 0c4aa7a3a0afc4814299773b79410e11553def03 Mon Sep 17 00:00:00 2001 From: ridwanullahi Date: Wed, 15 Mar 2023 01:19:33 +0100 Subject: [PATCH 16/16] update readme file --- app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 2275328..b434f67 100644 --- a/app.rb +++ b/app.rb @@ -32,7 +32,7 @@ def all_people end def create_person - print 'Do you want to create a Teacher (1) or teacher (2)? [input number]: ' + print 'Do you want to create a student (1) or teacher (2)? [input number]: ' type = gets.chomp.to_i case type when 1