From 27d914ba1af0b219639d1dfaafb0d7e1079d1fe9 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Mon, 29 May 2023 07:51:32 -0700 Subject: [PATCH 01/75] workflow --- .github/workflows/linters.yml | 20 ++++++++++++++++++++ .github/workflows/tests.yml | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/linters.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..60be81c --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,20 @@ +name: Linters + +on: pull_request + +jobs: + rubocop: + name: Rubocop + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + - 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/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..6534ae2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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: 2.6.x + - name: Setup RSpec + run: | + [ -f Gemfile ] && bundle --deployment + gem install --no-document rspec:'~>3.0' + - name: RSpec Report + run: rspec --force-color --format documentation \ No newline at end of file From 737709059d2d8739a47955dcfb64a66d981a2828 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Mon, 29 May 2023 07:51:55 -0700 Subject: [PATCH 02/75] rubocop --- .rubocop.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4efd805 --- /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: 25 +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 From c3ad0daec56cdaca956855ec5be6a5cf1bd4045c Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Mon, 29 May 2023 07:52:14 -0700 Subject: [PATCH 03/75] Gemfile --- Gemfile | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Gemfile diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..1a22d6d --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'rubocop', '>= 1.0', '< 2.0' From 464f7ee3307b4e45d5855facbd18454dd7ad355b Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Mon, 29 May 2023 07:52:29 -0700 Subject: [PATCH 04/75] app.rb --- app.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app.rb diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..4d4ebc6 --- /dev/null +++ b/app.rb @@ -0,0 +1,7 @@ +class App + def iniliaze + @books = [] + @people = [] + @rentals = [] + end +end From 39f27842c060dab5b9f3ae79e99a805c1a562c19 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Mon, 29 May 2023 07:52:42 -0700 Subject: [PATCH 05/75] item.rb --- item.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 item.rb diff --git a/item.rb b/item.rb new file mode 100644 index 0000000..0b1bb67 --- /dev/null +++ b/item.rb @@ -0,0 +1,22 @@ +class Item + attr_reader :id, :archived + attr_accessor :genre, :author, :label, :published_date + + def iniliaze(genre, author, label, published_date) + @id = Random.rand(1..1000) + @genre = genre + @author = author + @label = label + @published_date = published_date + @archived = false + end + + def can_be_archived? + age_in_years = Time.now.year - @published_date.year + age_in_years >= 10 + end + + def move_to_archive + @archived = true if can_be_archived? + end +end From 8bccb62fda4cddf0136cb9759eff7e12d174199f Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Mon, 29 May 2023 07:53:03 -0700 Subject: [PATCH 06/75] main.rb --- main.rb | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 0000000..6fe81cf --- /dev/null +++ b/main.rb @@ -0,0 +1,88 @@ +require_relative 'app' + +class MainMainu + @app = App.new + def user_options(choice) + menu_options = { + 1 => method(:list_books), + 2 => method(:list_music), + 3 => method(:list_games), + 4 => method(:list_genres), + 5 => method(:list_labels), + 6 => method(:list_authors), + 7 => method(:create_book), + 8 => method(:create_music), + 9 => method(:create_games), + 0 => method(:exit_app) + } + if menu_options.key?(choice) + menu_options[choice].call(app) + else + puts 'Invalid option, please try again!' + end + end + + def display + puts 'Welcome to your library' + puts 'Please choose an option' + puts '1. List all books' + puts '2. List all music albums' + puts '3. List all games' + puts '4. List all genres' + puts '5. List all labels' + puts '6. List all authors' + puts '7. Create a book' + puts '8. Create a music album' + puts '9. Create a game' + puts '0. Exit' + end + + def list_books(app) + app.list_books + end + + def list_music(app) + app.list_music + end + + def list_games(app) + app.list_games + end + + def list_genres(app) + app.list_genres + end + + def list_labels(app) + app.list_labels + end + + def list_authors(app) + app.list_authors + end + + def create_book(app) + app.create_book + end + + def create_music(app) + app.create_music + end + + def create_games(app) + app.create_games + end + + def exit_app(app) + app.exit_app + end +end + +def main + main_menu = MainMenu.new + loop do + main_menu.display + choice = gets.chomp.to_i + main_menu.user_options(choice) + end +end From 65c68a2f478870e7bc38a92fdd772408e2c0374b Mon Sep 17 00:00:00 2001 From: yodit93 Date: Mon, 29 May 2023 18:36:06 +0300 Subject: [PATCH 07/75] Add Gemfile.lock and update main.rb --- Gemfile.lock | 34 ++++++++++++++++++++++++++++++++++ LICENSE | 42 +++++++++++++++++++++--------------------- main.rb | 3 ++- 3 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..39da945 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,34 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + json (2.6.3) + parallel (1.23.0) + parser (3.2.2.1) + ast (~> 2.4.1) + rainbow (3.1.1) + regexp_parser (2.8.0) + rexml (3.2.5) + rubocop (1.51.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.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.1) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.4.2) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + rubocop (>= 1.0, < 2.0) + +BUNDLED WITH + 2.4.13 diff --git a/LICENSE b/LICENSE index f182899..0cf0262 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2023 Brhanu Hailu - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE 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 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2023 Brhanu Hailu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE 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 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/main.rb b/main.rb index 6fe81cf..b59a905 100644 --- a/main.rb +++ b/main.rb @@ -1,6 +1,6 @@ require_relative 'app' -class MainMainu +class MainMenu @app = App.new def user_options(choice) menu_options = { @@ -86,3 +86,4 @@ def main main_menu.user_options(choice) end end +main From 8f88f600a58b1bf56921cf854270f4c3dae4ef2d Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 11:22:41 +0300 Subject: [PATCH 08/75] Add a custom setter for label attribute --- item.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/item.rb b/item.rb index 0b1bb67..a6ccee3 100644 --- a/item.rb +++ b/item.rb @@ -1,12 +1,14 @@ +require_relative 'label' + class Item - attr_reader :id, :archived - attr_accessor :genre, :author, :label, :published_date + attr_reader :id, :archived, :label + attr_accessor :genre, :author, :published_date - def iniliaze(genre, author, label, published_date) + def initialize(genre, author, published_date) @id = Random.rand(1..1000) @genre = genre @author = author - @label = label + @label = nil @published_date = published_date @archived = false end @@ -19,4 +21,9 @@ def can_be_archived? def move_to_archive @archived = true if can_be_archived? end + + def label=(label) + @label = label + label.add_item(self) + end end From 8005b9c13133abfd3f90dcd149f3b71dd963cc30 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Tue, 30 May 2023 11:27:26 +0300 Subject: [PATCH 09/75] create music files --- .rspec | 1 + LICENSE | 2 +- README.md | 244 ++++++++++++++++++++++++++++++- spec/spec_helper.rb | 96 ++++++++++++ src/json_files/genres.json | 0 src/json_files/music_albums.json | 0 src/music/genre.rb | 27 ++++ src/music/music_album.rb | 29 ++++ 8 files changed, 397 insertions(+), 2 deletions(-) create mode 100644 .rspec create mode 100644 spec/spec_helper.rb create mode 100644 src/json_files/genres.json create mode 100644 src/json_files/music_albums.json create mode 100644 src/music/genre.rb create mode 100644 src/music/music_album.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..82b8369 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper \ No newline at end of file diff --git a/LICENSE b/LICENSE index 0cf0262..8f1d0fa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Brhanu Hailu +Copyright (c) 2023 Brhanu Hailu, Daniel Matama Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 75fc403..97022ae 100644 --- a/README.md +++ b/README.md @@ -1 +1,243 @@ -# capstone-ruby-practice \ No newline at end of file + + +
+ logo +
+ +

Catalogue_Of_My_Things

+ +
+ + + +# 📗 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) + - [Setup](#setup) + - [Prerequisites](#prerequisites) + - [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) +- [🙏 Acknowledgements](#acknowledgements) +- [❓ FAQ (OPTIONAL)](#faq) +- [📝 License](#license) + + + +# 📖 [Catalogue_Of_My_Things] + +**[Catalogue_Of_My_Things]** is a console app that will help to keep a record of different types of things one owns: books, music albums, movies, and games. Everything is based on the UML class diagram. The data is stored in JSON files but we also prepare a database with tables structure analogical the program's class structure. + +## 🛠 Built With + +### Tech Stack + +
+ Server + +
+ +
+Database + +
+ + + +### Key Features + +> Describe between 1-3 key features of the application. + +- **[key_feature_1]** +- **[key_feature_2]** +- **[key_feature_3]** + +

(back to top)

+ + + +## 🚀 Live Demo + +> Add a link to your deployed project. + +- [Live Demo Link](https://yourdeployedapplicationlink.com) + +

(back to top)

+ + + +## 💻 Getting Started + +> Describe how a new developer could make use of your project. + +To get a local copy up and running, follow these steps. + +### Prerequisites + +In order to run this project you need: + + + +### Setup + +Clone this repository to your desired folder: + + + +### Install + +Install this project with: + + + +### Usage + +To run the project, execute the following command: + + + +### Run tests + +To run tests, run the following command: + + + +### Deployment + +You can deploy this project using: + + + +

(back to top)

+ + + +## 👥 Authors + +> Mention all of the collaborators of this project. + +👤 **Daniel Matama** + +- GitHub: [@Recillah-Khamala](https://github.com/danielmatama) +- Twitter: [@recillahk](https://twitter.com/danmatama) +- LinkedIn: [Recillah Khamala](https://www.linkedin.com/in/danielmatama-mwebesa/) + +

(back to top)

+ + + +## 🔭 Future Features + +> Describe 1 - 3 features you will add to the project. + +- [ ] **[new_feature_1]** +- [ ] **[new_feature_2]** +- [ ] **[new_feature_3]** + +

(back to top)

+ + + +## 🤝 Contributing + +Contributions, issues, and feature requests are welcome! + +Feel free to check the [issues page](../../issues/). + +

(back to top)

+ + + +## ⭐️ Show your support + +> Write a message to encourage readers to support your project + +If you like this project... + +

(back to top)

+ + + +## 🙏 Acknowledgments + +> Give credit to everyone who inspired your codebase. + +I would like to thank... + +

(back to top)

+ + + +## ❓ FAQ (OPTIONAL) + +> Add at least 2 questions new developers would ask when they decide to use your project. + +- **[Question_1]** + + - [Answer_1] + +- **[Question_2]** + + - [Answer_2] + +

(back to top)

+ + + +## 📝 License + +This project is [MIT](./LICENSE) licensed. + +

(back to top)

\ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..f2a0c16 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,96 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # This setting enables warnings. It's recommended, but in some cases may + # # be too noisy due to issues in dependencies. + # config.warnings = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed +end diff --git a/src/json_files/genres.json b/src/json_files/genres.json new file mode 100644 index 0000000..e69de29 diff --git a/src/json_files/music_albums.json b/src/json_files/music_albums.json new file mode 100644 index 0000000..e69de29 diff --git a/src/music/genre.rb b/src/music/genre.rb new file mode 100644 index 0000000..2cc9ca4 --- /dev/null +++ b/src/music/genre.rb @@ -0,0 +1,27 @@ +# Create Genre class with an association to the Item class (in a separate .rb file). +# All Genre class properties visible in the diagram should be defined and set up in the constructor method. +# Implement methods: +# add_item method in the Genre class +# should take an instance of the Item class as an input +# should add the input item to the collection of items +# should add self as a property of the item object (by using the correct setter from the item object) +# Add unit tests for all implemented methods. +# The following options should be available: +# List all genres (e.g 'Comedy', 'Thriller') +# All data should be preserved by saving collections in .json files. +# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: +# genres table +class Genre + attr_reader :items, :name, :id + + def initialize(name, id: rand(1..1000)) + @id = id + @name = name + @items = [] + end + + def add_item(item) + @items << item + item.genres = self + end +end diff --git a/src/music/music_album.rb b/src/music/music_album.rb new file mode 100644 index 0000000..6f3aad0 --- /dev/null +++ b/src/music/music_album.rb @@ -0,0 +1,29 @@ +# Create MusicAlbum class in a separate .rb file. +# All MusicAlbum class properties visible in the diagram should be defined and set up in the constructor method. +# Implement methods: +# can_be_archived?() in the MusicAlbum class +# should override the method from the parent class +# should return true if parent's method returns true AND if on_spotify equals true +# otherwise, it should return false +# Add unit tests for all implemented methods. +# The following options should be available: +# List all music albums +# Add a music album +# All data should be preserved by saving collections in .json files. +# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: +# music_albums table (add all properties and associations from the parent Item class as table columns) +require_relative '../item' +class MusicAlbum < Item + attr_accessor :name, :publish_date, :on_spotify + + def initialize(name, publish_date, on_spotify) + @id = Random.rand(1..1000) + super(publish_date, archived) + @name = name + @on_spotify = on_spotify + end + + def can_be_archived? + super && @on_spotify + end +end From ad3811629fd8d007afe2f87d286ba7055a3a4d61 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 11:34:25 +0300 Subject: [PATCH 10/75] Create label class with attributes and method --- label.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 label.rb diff --git a/label.rb b/label.rb new file mode 100644 index 0000000..37ad6b8 --- /dev/null +++ b/label.rb @@ -0,0 +1,16 @@ +class Label + attr_reader :id + attr_accessor :title, :color, :items + + def initialize(title, color) + @id = Random.rand(1..1000) + @title = title + @color = color + @items = [] + end + + def add_item(item) + @items << item + item.label = self if item.label.nil? + end +end From 48a0db4ef23767446310147c127dc527190c1e95 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 11:34:46 +0300 Subject: [PATCH 11/75] Fix linter errors --- .github/workflows/linters.yml | 38 ++++---- .github/workflows/tests.yml | 36 +++---- .rubocop.yml | 106 ++++++++++---------- Gemfile | 6 +- Gemfile.lock | 68 ++++++------- app.rb | 14 +-- main.rb | 178 +++++++++++++++++----------------- 7 files changed, 224 insertions(+), 222 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 60be81c..e284163 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -1,20 +1,20 @@ -name: Linters - -on: pull_request - -jobs: - rubocop: - name: Rubocop - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v3 - - 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 +name: Linters + +on: pull_request + +jobs: + rubocop: + name: Rubocop + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + - 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/tests.yml b/.github/workflows/tests.yml index 6534ae2..ed1fedd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,19 +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: 2.6.x - - name: Setup RSpec - run: | - [ -f Gemfile ] && bundle --deployment - gem install --no-document rspec:'~>3.0' - - name: RSpec Report +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: 2.6.x + - name: Setup RSpec + run: | + [ -f Gemfile ] && bundle --deployment + gem install --no-document rspec:'~>3.0' + - name: RSpec Report run: rspec --force-color --format documentation \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 4efd805..dc7cd33 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,52 +1,54 @@ -AllCops: - NewCops: enable - Exclude: - - "Guardfile" - - "Rakefile" - - "node_modules/**/*" - - DisplayCopNames: true - -Layout/LineLength: - Max: 120 -Metrics/MethodLength: - Max: 25 -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 +AllCops: + NewCops: enable + Exclude: + - "Guardfile" + - "Rakefile" + - "node_modules/**/*" + + DisplayCopNames: true + +Layout/LineLength: + Max: 120 +Metrics/MethodLength: + Max: 25 +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 +Layout/EndOfLine: + Enabled: False \ No newline at end of file diff --git a/Gemfile b/Gemfile index 1a22d6d..b7683a4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source 'https://rubygems.org' - -gem 'rubocop', '>= 1.0', '< 2.0' +source 'https://rubygems.org' + +gem 'rubocop', '>= 1.0', '< 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 39da945..41ea951 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,34 +1,34 @@ -GEM - remote: https://rubygems.org/ - specs: - ast (2.4.2) - json (2.6.3) - parallel (1.23.0) - parser (3.2.2.1) - ast (~> 2.4.1) - rainbow (3.1.1) - regexp_parser (2.8.0) - rexml (3.2.5) - rubocop (1.51.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.28.0, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.28.1) - parser (>= 3.2.1.0) - ruby-progressbar (1.13.0) - unicode-display_width (2.4.2) - -PLATFORMS - x86_64-linux - -DEPENDENCIES - rubocop (>= 1.0, < 2.0) - -BUNDLED WITH - 2.4.13 +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + json (2.6.3) + parallel (1.23.0) + parser (3.2.2.1) + ast (~> 2.4.1) + rainbow (3.1.1) + regexp_parser (2.8.0) + rexml (3.2.5) + rubocop (1.51.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.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.1) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.4.2) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + rubocop (>= 1.0, < 2.0) + +BUNDLED WITH + 2.4.13 diff --git a/app.rb b/app.rb index 4d4ebc6..173f0e7 100644 --- a/app.rb +++ b/app.rb @@ -1,7 +1,7 @@ -class App - def iniliaze - @books = [] - @people = [] - @rentals = [] - end -end +class App + def iniliaze + @books = [] + @people = [] + @rentals = [] + end +end diff --git a/main.rb b/main.rb index b59a905..aa9c067 100644 --- a/main.rb +++ b/main.rb @@ -1,89 +1,89 @@ -require_relative 'app' - -class MainMenu - @app = App.new - def user_options(choice) - menu_options = { - 1 => method(:list_books), - 2 => method(:list_music), - 3 => method(:list_games), - 4 => method(:list_genres), - 5 => method(:list_labels), - 6 => method(:list_authors), - 7 => method(:create_book), - 8 => method(:create_music), - 9 => method(:create_games), - 0 => method(:exit_app) - } - if menu_options.key?(choice) - menu_options[choice].call(app) - else - puts 'Invalid option, please try again!' - end - end - - def display - puts 'Welcome to your library' - puts 'Please choose an option' - puts '1. List all books' - puts '2. List all music albums' - puts '3. List all games' - puts '4. List all genres' - puts '5. List all labels' - puts '6. List all authors' - puts '7. Create a book' - puts '8. Create a music album' - puts '9. Create a game' - puts '0. Exit' - end - - def list_books(app) - app.list_books - end - - def list_music(app) - app.list_music - end - - def list_games(app) - app.list_games - end - - def list_genres(app) - app.list_genres - end - - def list_labels(app) - app.list_labels - end - - def list_authors(app) - app.list_authors - end - - def create_book(app) - app.create_book - end - - def create_music(app) - app.create_music - end - - def create_games(app) - app.create_games - end - - def exit_app(app) - app.exit_app - end -end - -def main - main_menu = MainMenu.new - loop do - main_menu.display - choice = gets.chomp.to_i - main_menu.user_options(choice) - end -end -main +require_relative 'app' + +class MainMenu + @app = App.new + def user_options(choice) + menu_options = { + 1 => method(:list_books), + 2 => method(:list_music), + 3 => method(:list_games), + 4 => method(:list_genres), + 5 => method(:list_labels), + 6 => method(:list_authors), + 7 => method(:create_book), + 8 => method(:create_music), + 9 => method(:create_games), + 0 => method(:exit_app) + } + if menu_options.key?(choice) + menu_options[choice].call(app) + else + puts 'Invalid option, please try again!' + end + end + + def display + puts 'Welcome to your library' + puts 'Please choose an option' + puts '1. List all books' + puts '2. List all music albums' + puts '3. List all games' + puts '4. List all genres' + puts '5. List all labels' + puts '6. List all authors' + puts '7. Create a book' + puts '8. Create a music album' + puts '9. Create a game' + puts '0. Exit' + end + + def list_books(app) + app.list_books + end + + def list_music(app) + app.list_music + end + + def list_games(app) + app.list_games + end + + def list_genres(app) + app.list_genres + end + + def list_labels(app) + app.list_labels + end + + def list_authors(app) + app.list_authors + end + + def create_book(app) + app.create_book + end + + def create_music(app) + app.create_music + end + + def create_games(app) + app.create_games + end + + def exit_app(app) + app.exit_app + end +end + +def main + main_menu = MainMenu.new + loop do + main_menu.display + choice = gets.chomp.to_i + main_menu.user_options(choice) + end +end +main From b9826caabeb60ae2e53539743ac6e62c9e94964b Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 02:38:51 -0700 Subject: [PATCH 12/75] authors --- author.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 author.rb diff --git a/author.rb b/author.rb new file mode 100644 index 0000000..933a95d --- /dev/null +++ b/author.rb @@ -0,0 +1,22 @@ +require_relative 'item' + +class Author + attr_reader :id + attr_accessor :first_name, :last_name, :items + + def initialize(first_name, last_name, _item) + @id = Random.rand(1..1000) + @first_name = first_name + @last_name = last_name + @items = [] + end + + def full_name + "#{@first_name} #{@last_name}" + end + + def add_author(item) + @items.push(item) + item.author = self + end +end From ccf7f9661e375e895cdc4e2a92aa999290a4f5c8 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 02:39:04 -0700 Subject: [PATCH 13/75] game.rb --- game.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 game.rb diff --git a/game.rb b/game.rb new file mode 100644 index 0000000..3e443c3 --- /dev/null +++ b/game.rb @@ -0,0 +1,20 @@ +class Game < Item + attr_accessor :multiplayer, :last_played_date + + def initialize(genre, author, published_date, multiplayer, last_played_date) + super(genre, author, label, published_date) + @multiplayer = multiplayer + @last_played_date = last_played_date + end + + def move_to_archive + @archived = true if can_be_archived? + end + + private + + def can_be_archived? + age_in_years = Time.now.year - @last_played_date.year + age_in_years >= 10 + end +end From 8fe60026f367ee420c0e93b16fbfb3c0a24cb97e Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 12:53:20 +0300 Subject: [PATCH 14/75] Create book class as child of item class --- book.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 book.rb diff --git a/book.rb b/book.rb new file mode 100644 index 0000000..2babc87 --- /dev/null +++ b/book.rb @@ -0,0 +1,14 @@ +require_relative 'item' + +class Book < Item + def initialize(genre, author, published_date, publisher, cover_state) + super(genre, author, published_date) + @publisher = publisher + @cover_state = cover_state + end + + def can_be_archived? + result = super + result || cover_state == 'bad' + end +end From 864675a9644941d0138283777290905798f5a657 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 14:37:14 +0300 Subject: [PATCH 15/75] Add methods for book and label classes --- app.rb | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/app.rb b/app.rb index 173f0e7..a6623c3 100644 --- a/app.rb +++ b/app.rb @@ -1,7 +1,52 @@ +require_relative 'book' +require_relative 'label' + class App - def iniliaze + def initialize @books = [] - @people = [] - @rentals = [] + @labels = [] + end + + def list_books + @books.each do |book| + puts "#{book.id} - #{book.genre} - #{book.author} - #{book.published_date}" + end + end + + def list_labels + @labels.each do |label| + puts "#{label.id} - #{label.title} - #{label.color}" + end + end + + def create_book + puts 'Enter genre' + genre = gets.chomp + puts 'Enter author' + author = gets.chomp + puts 'Enter published date (YYYY-MM-DD))' + published_date = gets.chomp + puts 'Enter publisher' + publisher = gets.chomp + puts 'Enter cover state' + cover_state = gets.chomp + book = Book.new(genre, author, published_date, publisher, cover_state) + @books << book + puts 'Book created successfully' + end + + def create_label + puts 'Enter title' + title = gets.chomp + puts 'Enter color' + color = gets.chomp + label = Label.new(title, color) + @labels << label + puts 'Label created successfully' + end + + def exit_app + puts 'Thanks for using the app!' + exit end end From dd00944f975da80e6aac5ff57d3acbacd37f74af Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 14:37:53 +0300 Subject: [PATCH 16/75] Update main.rb to include option for creating label --- main.rb | 190 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 101 insertions(+), 89 deletions(-) diff --git a/main.rb b/main.rb index aa9c067..18de710 100644 --- a/main.rb +++ b/main.rb @@ -1,89 +1,101 @@ -require_relative 'app' - -class MainMenu - @app = App.new - def user_options(choice) - menu_options = { - 1 => method(:list_books), - 2 => method(:list_music), - 3 => method(:list_games), - 4 => method(:list_genres), - 5 => method(:list_labels), - 6 => method(:list_authors), - 7 => method(:create_book), - 8 => method(:create_music), - 9 => method(:create_games), - 0 => method(:exit_app) - } - if menu_options.key?(choice) - menu_options[choice].call(app) - else - puts 'Invalid option, please try again!' - end - end - - def display - puts 'Welcome to your library' - puts 'Please choose an option' - puts '1. List all books' - puts '2. List all music albums' - puts '3. List all games' - puts '4. List all genres' - puts '5. List all labels' - puts '6. List all authors' - puts '7. Create a book' - puts '8. Create a music album' - puts '9. Create a game' - puts '0. Exit' - end - - def list_books(app) - app.list_books - end - - def list_music(app) - app.list_music - end - - def list_games(app) - app.list_games - end - - def list_genres(app) - app.list_genres - end - - def list_labels(app) - app.list_labels - end - - def list_authors(app) - app.list_authors - end - - def create_book(app) - app.create_book - end - - def create_music(app) - app.create_music - end - - def create_games(app) - app.create_games - end - - def exit_app(app) - app.exit_app - end -end - -def main - main_menu = MainMenu.new - loop do - main_menu.display - choice = gets.chomp.to_i - main_menu.user_options(choice) - end -end -main +require_relative 'app' + +class MainMenu + attr_reader :app + + def initialize(app) + @app = app + end + + def user_options(choice) + menu_options = { + 1 => method(:list_books), + 2 => method(:list_music), + 3 => method(:list_games), + 4 => method(:list_genres), + 5 => method(:list_labels), + 6 => method(:list_authors), + 7 => method(:create_book), + 8 => method(:create_music), + 9 => method(:create_games), + 10 => method(:create_label), + 0 => method(:exit_app) + } + if menu_options.key?(choice) + menu_options[choice].call(app) + else + puts 'Invalid option, please try again!' + end + end + + def display + puts 'Welcome to your library' + puts 'Please choose an option' + puts '1. List all books' + puts '2. List all music albums' + puts '3. List all games' + puts '4. List all genres' + puts '5. List all labels' + puts '6. List all authors' + puts '7. Create a book' + puts '8. Create a music album' + puts '9. Create a game' + puts '10. Create a label' + puts '0. Exit' + end + + def list_books(app) + app.list_books + end + + def list_music(app) + app.list_music + end + + def list_games(app) + app.list_games + end + + def list_genres(app) + app.list_genres + end + + def list_labels(app) + app.list_labels + end + + def list_authors(app) + app.list_authors + end + + def create_book(app) + app.create_book + end + + def create_music(app) + app.create_music + end + + def create_games(app) + app.create_games + end + + def create_label(app) + app.create_label + end + + def exit_app(app) + app.exit_app + end +end + +def main + app = App.new + main_menu = MainMenu.new(app) + loop do + main_menu.display + choice = gets.chomp.to_i + main_menu.user_options(choice) + end +end +main From 5b2e79e66a6e4753dc1850f881621fa06cfccb65 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 17:47:22 +0300 Subject: [PATCH 17/75] Add methods for creating and listing book and label classes --- app.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app.rb b/app.rb index a6623c3..650757a 100644 --- a/app.rb +++ b/app.rb @@ -1,5 +1,7 @@ require_relative 'book' require_relative 'label' +require_relative './store/preserve_data' +require 'json' class App def initialize @@ -30,19 +32,15 @@ def create_book publisher = gets.chomp puts 'Enter cover state' cover_state = gets.chomp - book = Book.new(genre, author, published_date, publisher, cover_state) + puts 'Enter label title' + label_title = gets.chomp + puts 'Enter label color' + label_color = gets.chomp + label = Label.new(label_title, label_color) + book = Book.new(genre, author, published_date, publisher, cover_state, label) @books << book - puts 'Book created successfully' - end - - def create_label - puts 'Enter title' - title = gets.chomp - puts 'Enter color' - color = gets.chomp - label = Label.new(title, color) @labels << label - puts 'Label created successfully' + puts 'Book created successfully' end def exit_app From 9190cb1202d3202818617c682c32a65ad975825e Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 17:47:58 +0300 Subject: [PATCH 18/75] Update book label property --- book.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/book.rb b/book.rb index 2babc87..69bf963 100644 --- a/book.rb +++ b/book.rb @@ -1,8 +1,9 @@ require_relative 'item' class Book < Item - def initialize(genre, author, published_date, publisher, cover_state) - super(genre, author, published_date) + attr_accessor :publisher, :cover_state + def initialize(genre, author, published_date, publisher, cover_state, label = nil) + super(genre, author, published_date, label) @publisher = publisher @cover_state = cover_state end From a9e13c513aef9a7fc076d068851f3b64a288380a Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 17:48:40 +0300 Subject: [PATCH 19/75] Update item label property --- item.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/item.rb b/item.rb index a6ccee3..cf5001e 100644 --- a/item.rb +++ b/item.rb @@ -4,11 +4,11 @@ class Item attr_reader :id, :archived, :label attr_accessor :genre, :author, :published_date - def initialize(genre, author, published_date) + def initialize(genre, author, published_date, label = nil) @id = Random.rand(1..1000) @genre = genre @author = author - @label = nil + @label = label @published_date = published_date @archived = false end From 2971f92b87b047814dfbdc8d2939b8865d1cf101 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 17:49:35 +0300 Subject: [PATCH 20/75] Update main.rb and label.rb --- label.rb | 3 +-- main.rb | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/label.rb b/label.rb index 37ad6b8..051f0d2 100644 --- a/label.rb +++ b/label.rb @@ -1,6 +1,5 @@ class Label - attr_reader :id - attr_accessor :title, :color, :items + attr_accessor :title, :color, :items, :id def initialize(title, color) @id = Random.rand(1..1000) diff --git a/main.rb b/main.rb index 18de710..f07e8a1 100644 --- a/main.rb +++ b/main.rb @@ -18,7 +18,6 @@ def user_options(choice) 7 => method(:create_book), 8 => method(:create_music), 9 => method(:create_games), - 10 => method(:create_label), 0 => method(:exit_app) } if menu_options.key?(choice) @@ -40,7 +39,6 @@ def display puts '7. Create a book' puts '8. Create a music album' puts '9. Create a game' - puts '10. Create a label' puts '0. Exit' end @@ -80,10 +78,6 @@ def create_games(app) app.create_games end - def create_label(app) - app.create_label - end - def exit_app(app) app.exit_app end From 056cdbbbabc0ade980c9c29a5f30c2a689c2f08b Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 18:02:18 +0300 Subject: [PATCH 21/75] Fix linter errors --- app.rb | 4 +--- book.rb | 7 ++++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app.rb b/app.rb index 650757a..6687a36 100644 --- a/app.rb +++ b/app.rb @@ -22,8 +22,6 @@ def list_labels end def create_book - puts 'Enter genre' - genre = gets.chomp puts 'Enter author' author = gets.chomp puts 'Enter published date (YYYY-MM-DD))' @@ -37,7 +35,7 @@ def create_book puts 'Enter label color' label_color = gets.chomp label = Label.new(label_title, label_color) - book = Book.new(genre, author, published_date, publisher, cover_state, label) + book = Book.new(author, published_date, publisher, cover_state, label) @books << book @labels << label puts 'Book created successfully' diff --git a/book.rb b/book.rb index 69bf963..80bc69d 100644 --- a/book.rb +++ b/book.rb @@ -1,9 +1,10 @@ require_relative 'item' class Book < Item - attr_accessor :publisher, :cover_state - def initialize(genre, author, published_date, publisher, cover_state, label = nil) - super(genre, author, published_date, label) + attr_accessor :publisher, :cover_state + + def initialize(author, published_date, publisher, cover_state, label = nil) + super(author, published_date, label) @publisher = publisher @cover_state = cover_state end From 6146da550a1680ae1510fbcad89b6bae999bdf23 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 21:25:10 +0300 Subject: [PATCH 22/75] Create store with preserve_data class --- store/books.json | 86 ++++++++++++++++++++++++++++++++++++++++++ store/labels.json | 37 ++++++++++++++++++ store/preserve_data.rb | 10 +++++ 3 files changed, 133 insertions(+) create mode 100644 store/books.json create mode 100644 store/labels.json create mode 100644 store/preserve_data.rb diff --git a/store/books.json b/store/books.json new file mode 100644 index 0000000..74b0a2c --- /dev/null +++ b/store/books.json @@ -0,0 +1,86 @@ +[ + { + "id": 535, + "author": "author1", + "published_date": "2010-09-09", + "publisher": "pub", + "cover_state": "good", + "label": { + "id": 476, + "title": "fiction", + "color": "green" + } + }, + { + "id": 256, + "author": "author2", + "published_date": "1998-07-30", + "publisher": "pubmed", + "cover_state": "bad", + "label": { + "id": 84, + "title": "title2", + "color": "orange" + } + }, + { + "id": 345, + "author": "author3", + "published_date": "1765-03-14", + "publisher": "pubmed", + "cover_state": "bad", + "label": { + "id": 170, + "title": "science", + "color": "red" + } + }, + { + "id": 858, + "author": "a", + "published_date": "2017-08-04", + "publisher": "pub", + "cover_state": "good", + "label": { + "id": 181, + "title": "history", + "color": "violet" + } + }, + { + "id": 844, + "author": "yod", + "published_date": "220-09-25", + "publisher": "Biomed", + "cover_state": "good", + "label": { + "id": 157, + "title": "Science", + "color": "yellow" + } + }, + { + "id": 973, + "author": "John", + "published_date": "1990-12-12", + "publisher": "Nasa", + "cover_state": "bad", + "label": { + "id": 918, + "title": "Robotic", + "color": "dark" + } + }, + { + "id": 206, + "author": "a", + "published_date": "1888-02-02", + "publisher": "pub", + "cover_state": "bad", + "label": { + "id": 214, + "title": "iction", + "color": "red" + } + } +] \ No newline at end of file diff --git a/store/labels.json b/store/labels.json new file mode 100644 index 0000000..a29fdf6 --- /dev/null +++ b/store/labels.json @@ -0,0 +1,37 @@ +[ + { + "id": 476, + "title": "fiction", + "color": "green" + }, + { + "id": 84, + "title": "title2", + "color": "orange" + }, + { + "id": 170, + "title": "science", + "color": "red" + }, + { + "id": 181, + "title": "history", + "color": "violet" + }, + { + "id": 157, + "title": "Science", + "color": "yellow" + }, + { + "id": 918, + "title": "Robotic", + "color": "dark" + }, + { + "id": 214, + "title": "iction", + "color": "red" + } +] \ No newline at end of file diff --git a/store/preserve_data.rb b/store/preserve_data.rb new file mode 100644 index 0000000..01aaa88 --- /dev/null +++ b/store/preserve_data.rb @@ -0,0 +1,10 @@ +class PreserveData + def save_data(data, filename) + data = JSON.pretty_generate(data) + File.write(filename, data) + end + + def load_data(filename) + JSON.parse(File.read(filename)) + end +end From e50a298736d089f6851ad5b81dcd7476c3bf7ee6 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 21:26:07 +0300 Subject: [PATCH 23/75] Save created books and labels --- app.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/app.rb b/app.rb index 6687a36..790bd0b 100644 --- a/app.rb +++ b/app.rb @@ -5,19 +5,20 @@ class App def initialize - @books = [] - @labels = [] + @store = PreserveData.new + @books = File.empty?('./store/books.json') ? [] : @store.load_data('./store/books.json') + @labels = File.empty?('./store/labels.json') ? [] : @store.load_data('./store/labels.json') end def list_books @books.each do |book| - puts "#{book.id} - #{book.genre} - #{book.author} - #{book.published_date}" + puts "#{book['id']} - #{book['author']} - #{book['published_date']}" end end def list_labels @labels.each do |label| - puts "#{label.id} - #{label.title} - #{label.color}" + puts "#{label['id']} - #{label['title']} - #{label['color']}" end end @@ -34,13 +35,32 @@ def create_book label_title = gets.chomp puts 'Enter label color' label_color = gets.chomp - label = Label.new(label_title, label_color) - book = Book.new(author, published_date, publisher, cover_state, label) + label = create_label(label_title, label_color) + book = create_book_object(author, published_date, publisher, cover_state, label) @books << book @labels << label + @store.save_data(@books, './store/books.json') + @store.save_data(@labels, './store/labels.json') puts 'Book created successfully' end + def create_label(title, color) + label = Label.new(title, color) + { 'id' => label.id, 'title' => label.title, 'color' => label.color } + end + + def create_book_object(author, published_date, publisher, cover_state, label) + book = Book.new(author, published_date, publisher, cover_state, label) + { + 'id' => book.id, + 'author' => book.author, + 'published_date' => book.published_date, + 'publisher' => book.publisher, + 'cover_state' => book.cover_state, + 'label' => book.label + } + end + def exit_app puts 'Thanks for using the app!' exit From 5256767717d65ce6a22f980f707dab329de52fa4 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Tue, 30 May 2023 21:26:30 +0300 Subject: [PATCH 24/75] Fix linter errors --- README.md | 484 +++++++++++++++++++-------------------- author.rb | 44 ++-- book.rb | 32 +-- game.rb | 40 ++-- item.rb | 58 ++--- label.rb | 30 +-- main.rb | 190 +++++++-------- spec/spec_helper.rb | 192 ++++++++-------- src/music/genre.rb | 54 ++--- src/music/music_album.rb | 58 ++--- 10 files changed, 591 insertions(+), 591 deletions(-) diff --git a/README.md b/README.md index 97022ae..3a71cc8 100644 --- a/README.md +++ b/README.md @@ -1,243 +1,243 @@ - - -
- logo -
- -

Catalogue_Of_My_Things

- -
- - - -# 📗 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) - - [Setup](#setup) - - [Prerequisites](#prerequisites) - - [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) -- [🙏 Acknowledgements](#acknowledgements) -- [❓ FAQ (OPTIONAL)](#faq) -- [📝 License](#license) - - - -# 📖 [Catalogue_Of_My_Things] - -**[Catalogue_Of_My_Things]** is a console app that will help to keep a record of different types of things one owns: books, music albums, movies, and games. Everything is based on the UML class diagram. The data is stored in JSON files but we also prepare a database with tables structure analogical the program's class structure. - -## 🛠 Built With - -### Tech Stack - -
- Server - -
- -
-Database - -
- - - -### Key Features - -> Describe between 1-3 key features of the application. - -- **[key_feature_1]** -- **[key_feature_2]** -- **[key_feature_3]** - -

(back to top)

- - - -## 🚀 Live Demo - -> Add a link to your deployed project. - -- [Live Demo Link](https://yourdeployedapplicationlink.com) - -

(back to top)

- - - -## 💻 Getting Started - -> Describe how a new developer could make use of your project. - -To get a local copy up and running, follow these steps. - -### Prerequisites - -In order to run this project you need: - - - -### Setup - -Clone this repository to your desired folder: - - - -### Install - -Install this project with: - - - -### Usage - -To run the project, execute the following command: - - - -### Run tests - -To run tests, run the following command: - - - -### Deployment - -You can deploy this project using: - - - -

(back to top)

- - - -## 👥 Authors - -> Mention all of the collaborators of this project. - -👤 **Daniel Matama** - -- GitHub: [@Recillah-Khamala](https://github.com/danielmatama) -- Twitter: [@recillahk](https://twitter.com/danmatama) -- LinkedIn: [Recillah Khamala](https://www.linkedin.com/in/danielmatama-mwebesa/) - -

(back to top)

- - - -## 🔭 Future Features - -> Describe 1 - 3 features you will add to the project. - -- [ ] **[new_feature_1]** -- [ ] **[new_feature_2]** -- [ ] **[new_feature_3]** - -

(back to top)

- - - -## 🤝 Contributing - -Contributions, issues, and feature requests are welcome! - -Feel free to check the [issues page](../../issues/). - -

(back to top)

- - - -## ⭐️ Show your support - -> Write a message to encourage readers to support your project - -If you like this project... - -

(back to top)

- - - -## 🙏 Acknowledgments - -> Give credit to everyone who inspired your codebase. - -I would like to thank... - -

(back to top)

- - - -## ❓ FAQ (OPTIONAL) - -> Add at least 2 questions new developers would ask when they decide to use your project. - -- **[Question_1]** - - - [Answer_1] - -- **[Question_2]** - - - [Answer_2] - -

(back to top)

- - - -## 📝 License - -This project is [MIT](./LICENSE) licensed. - + + +
+ logo +
+ +

Catalogue_Of_My_Things

+ +
+ + + +# 📗 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) + - [Setup](#setup) + - [Prerequisites](#prerequisites) + - [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) +- [🙏 Acknowledgements](#acknowledgements) +- [❓ FAQ (OPTIONAL)](#faq) +- [📝 License](#license) + + + +# 📖 [Catalogue_Of_My_Things] + +**[Catalogue_Of_My_Things]** is a console app that will help to keep a record of different types of things one owns: books, music albums, movies, and games. Everything is based on the UML class diagram. The data is stored in JSON files but we also prepare a database with tables structure analogical the program's class structure. + +## 🛠 Built With + +### Tech Stack + +
+ Server + +
+ +
+Database + +
+ + + +### Key Features + +> Describe between 1-3 key features of the application. + +- **[key_feature_1]** +- **[key_feature_2]** +- **[key_feature_3]** + +

(back to top)

+ + + +## 🚀 Live Demo + +> Add a link to your deployed project. + +- [Live Demo Link](https://yourdeployedapplicationlink.com) + +

(back to top)

+ + + +## 💻 Getting Started + +> Describe how a new developer could make use of your project. + +To get a local copy up and running, follow these steps. + +### Prerequisites + +In order to run this project you need: + + + +### Setup + +Clone this repository to your desired folder: + + + +### Install + +Install this project with: + + + +### Usage + +To run the project, execute the following command: + + + +### Run tests + +To run tests, run the following command: + + + +### Deployment + +You can deploy this project using: + + + +

(back to top)

+ + + +## 👥 Authors + +> Mention all of the collaborators of this project. + +👤 **Daniel Matama** + +- GitHub: [@Recillah-Khamala](https://github.com/danielmatama) +- Twitter: [@recillahk](https://twitter.com/danmatama) +- LinkedIn: [Recillah Khamala](https://www.linkedin.com/in/danielmatama-mwebesa/) + +

(back to top)

+ + + +## 🔭 Future Features + +> Describe 1 - 3 features you will add to the project. + +- [ ] **[new_feature_1]** +- [ ] **[new_feature_2]** +- [ ] **[new_feature_3]** + +

(back to top)

+ + + +## 🤝 Contributing + +Contributions, issues, and feature requests are welcome! + +Feel free to check the [issues page](../../issues/). + +

(back to top)

+ + + +## ⭐️ Show your support + +> Write a message to encourage readers to support your project + +If you like this project... + +

(back to top)

+ + + +## 🙏 Acknowledgments + +> Give credit to everyone who inspired your codebase. + +I would like to thank... + +

(back to top)

+ + + +## ❓ FAQ (OPTIONAL) + +> Add at least 2 questions new developers would ask when they decide to use your project. + +- **[Question_1]** + + - [Answer_1] + +- **[Question_2]** + + - [Answer_2] + +

(back to top)

+ + + +## 📝 License + +This project is [MIT](./LICENSE) licensed. +

(back to top)

\ No newline at end of file diff --git a/author.rb b/author.rb index 933a95d..e800f57 100644 --- a/author.rb +++ b/author.rb @@ -1,22 +1,22 @@ -require_relative 'item' - -class Author - attr_reader :id - attr_accessor :first_name, :last_name, :items - - def initialize(first_name, last_name, _item) - @id = Random.rand(1..1000) - @first_name = first_name - @last_name = last_name - @items = [] - end - - def full_name - "#{@first_name} #{@last_name}" - end - - def add_author(item) - @items.push(item) - item.author = self - end -end +require_relative 'item' + +class Author + attr_reader :id + attr_accessor :first_name, :last_name, :items + + def initialize(first_name, last_name, _item) + @id = Random.rand(1..1000) + @first_name = first_name + @last_name = last_name + @items = [] + end + + def full_name + "#{@first_name} #{@last_name}" + end + + def add_author(item) + @items.push(item) + item.author = self + end +end diff --git a/book.rb b/book.rb index 80bc69d..3aa4727 100644 --- a/book.rb +++ b/book.rb @@ -1,16 +1,16 @@ -require_relative 'item' - -class Book < Item - attr_accessor :publisher, :cover_state - - def initialize(author, published_date, publisher, cover_state, label = nil) - super(author, published_date, label) - @publisher = publisher - @cover_state = cover_state - end - - def can_be_archived? - result = super - result || cover_state == 'bad' - end -end +require_relative 'item' + +class Book < Item + attr_accessor :publisher, :cover_state + + def initialize(author, published_date, publisher, cover_state, label = nil) + super(nil, author, published_date, label) + @publisher = publisher + @cover_state = cover_state + end + + def can_be_archived? + result = super + result || cover_state == 'bad' + end +end diff --git a/game.rb b/game.rb index 3e443c3..4ab5db9 100644 --- a/game.rb +++ b/game.rb @@ -1,20 +1,20 @@ -class Game < Item - attr_accessor :multiplayer, :last_played_date - - def initialize(genre, author, published_date, multiplayer, last_played_date) - super(genre, author, label, published_date) - @multiplayer = multiplayer - @last_played_date = last_played_date - end - - def move_to_archive - @archived = true if can_be_archived? - end - - private - - def can_be_archived? - age_in_years = Time.now.year - @last_played_date.year - age_in_years >= 10 - end -end +class Game < Item + attr_accessor :multiplayer, :last_played_date + + def initialize(genre, author, published_date, multiplayer, last_played_date) + super(genre, author, label, published_date) + @multiplayer = multiplayer + @last_played_date = last_played_date + end + + def move_to_archive + @archived = true if can_be_archived? + end + + private + + def can_be_archived? + age_in_years = Time.now.year - @last_played_date.year + age_in_years >= 10 + end +end diff --git a/item.rb b/item.rb index cf5001e..91cb95c 100644 --- a/item.rb +++ b/item.rb @@ -1,29 +1,29 @@ -require_relative 'label' - -class Item - attr_reader :id, :archived, :label - attr_accessor :genre, :author, :published_date - - def initialize(genre, author, published_date, label = nil) - @id = Random.rand(1..1000) - @genre = genre - @author = author - @label = label - @published_date = published_date - @archived = false - end - - def can_be_archived? - age_in_years = Time.now.year - @published_date.year - age_in_years >= 10 - end - - def move_to_archive - @archived = true if can_be_archived? - end - - def label=(label) - @label = label - label.add_item(self) - end -end +require_relative 'label' + +class Item + attr_reader :id, :archived, :label + attr_accessor :genre, :author, :published_date + + def initialize(genre, author, published_date, label = nil) + @id = Random.rand(1..1000) + @genre = genre + @author = author + @label = label + @published_date = published_date + @archived = false + end + + def can_be_archived? + age_in_years = Time.now.year - @published_date.year + age_in_years >= 10 + end + + def move_to_archive + @archived = true if can_be_archived? + end + + def label=(label) + @label = label + label.add_item(self) + end +end diff --git a/label.rb b/label.rb index 051f0d2..8b44ec5 100644 --- a/label.rb +++ b/label.rb @@ -1,15 +1,15 @@ -class Label - attr_accessor :title, :color, :items, :id - - def initialize(title, color) - @id = Random.rand(1..1000) - @title = title - @color = color - @items = [] - end - - def add_item(item) - @items << item - item.label = self if item.label.nil? - end -end +class Label + attr_accessor :title, :color, :items, :id + + def initialize(title, color) + @id = Random.rand(1..1000) + @title = title + @color = color + @items = [] + end + + def add_item(item) + @items << item + item.label = self if item.label.nil? + end +end diff --git a/main.rb b/main.rb index f07e8a1..754d6da 100644 --- a/main.rb +++ b/main.rb @@ -1,95 +1,95 @@ -require_relative 'app' - -class MainMenu - attr_reader :app - - def initialize(app) - @app = app - end - - def user_options(choice) - menu_options = { - 1 => method(:list_books), - 2 => method(:list_music), - 3 => method(:list_games), - 4 => method(:list_genres), - 5 => method(:list_labels), - 6 => method(:list_authors), - 7 => method(:create_book), - 8 => method(:create_music), - 9 => method(:create_games), - 0 => method(:exit_app) - } - if menu_options.key?(choice) - menu_options[choice].call(app) - else - puts 'Invalid option, please try again!' - end - end - - def display - puts 'Welcome to your library' - puts 'Please choose an option' - puts '1. List all books' - puts '2. List all music albums' - puts '3. List all games' - puts '4. List all genres' - puts '5. List all labels' - puts '6. List all authors' - puts '7. Create a book' - puts '8. Create a music album' - puts '9. Create a game' - puts '0. Exit' - end - - def list_books(app) - app.list_books - end - - def list_music(app) - app.list_music - end - - def list_games(app) - app.list_games - end - - def list_genres(app) - app.list_genres - end - - def list_labels(app) - app.list_labels - end - - def list_authors(app) - app.list_authors - end - - def create_book(app) - app.create_book - end - - def create_music(app) - app.create_music - end - - def create_games(app) - app.create_games - end - - def exit_app(app) - app.exit_app - end -end - -def main - app = App.new - main_menu = MainMenu.new(app) - loop do - main_menu.display - choice = gets.chomp.to_i - main_menu.user_options(choice) - end -end -main +require_relative 'app' + +class MainMenu + attr_reader :app + + def initialize(app) + @app = app + end + + def user_options(choice) + menu_options = { + 1 => method(:list_books), + 2 => method(:list_music), + 3 => method(:list_games), + 4 => method(:list_genres), + 5 => method(:list_labels), + 6 => method(:list_authors), + 7 => method(:create_book), + 8 => method(:create_music), + 9 => method(:create_games), + 0 => method(:exit_app) + } + if menu_options.key?(choice) + menu_options[choice].call(app) + else + puts 'Invalid option, please try again!' + end + end + + def display + puts 'Welcome to your library' + puts 'Please choose an option' + puts '1. List all books' + puts '2. List all music albums' + puts '3. List all games' + puts '4. List all genres' + puts '5. List all labels' + puts '6. List all authors' + puts '7. Create a book' + puts '8. Create a music album' + puts '9. Create a game' + puts '0. Exit' + end + + def list_books(app) + app.list_books + end + + def list_music(app) + app.list_music + end + + def list_games(app) + app.list_games + end + + def list_genres(app) + app.list_genres + end + + def list_labels(app) + app.list_labels + end + + def list_authors(app) + app.list_authors + end + + def create_book(app) + app.create_book + end + + def create_music(app) + app.create_music + end + + def create_games(app) + app.create_games + end + + def exit_app(app) + app.exit_app + end +end + +def main + app = App.new + main_menu = MainMenu.new(app) + loop do + main_menu.display + choice = gets.chomp.to_i + main_menu.user_options(choice) + end +end +main diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f2a0c16..0f4e1b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,96 +1,96 @@ -# This file was generated by the `rspec --init` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration -RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. - config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end - - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. - config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. - mocks.verify_partial_doubles = true - end - - # This option will default to `:apply_to_host_groups` in RSpec 4 (and will - # have no way to turn it off -- the option exists only for backwards - # compatibility in RSpec 3). It causes shared context metadata to be - # inherited by the metadata hash of host groups and examples, rather than - # triggering implicit auto-inclusion in groups with matching metadata. - config.shared_context_metadata_behavior = :apply_to_host_groups - - # The settings below are suggested to provide a good initial experience - # with RSpec, but feel free to customize to your heart's content. - # # This allows you to limit a spec run to individual examples or groups - # # you care about by tagging them with `:focus` metadata. When nothing - # # is tagged with `:focus`, all examples get run. RSpec also provides - # # aliases for `it`, `describe`, and `context` that include `:focus` - # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - # config.filter_run_when_matching :focus - # - # # Allows RSpec to persist some state between runs in order to support - # # the `--only-failures` and `--next-failure` CLI options. We recommend - # # you configure your source control system to ignore this file. - # config.example_status_persistence_file_path = "spec/examples.txt" - # - # # Limits the available syntax to the non-monkey patched syntax that is - # # recommended. For more details, see: - # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode - # config.disable_monkey_patching! - # - # # This setting enables warnings. It's recommended, but in some cases may - # # be too noisy due to issues in dependencies. - # config.warnings = true - # - # # Many RSpec users commonly either run the entire suite or an individual - # # file, and it's useful to allow more verbose output when running an - # # individual spec file. - # if config.files_to_run.one? - # # Use the documentation formatter for detailed output, - # # unless a formatter has already been configured - # # (e.g. via a command-line flag). - # config.default_formatter = "doc" - # end - # - # # Print the 10 slowest examples and example groups at the - # # end of the spec run, to help surface which specs are running - # # particularly slow. - # config.profile_examples = 10 - # - # # Run specs in random order to surface order dependencies. If you find an - # # order dependency and want to debug it, you can fix the order by providing - # # the seed, which is printed after each run. - # # --seed 1234 - # config.order = :random - # - # # Seed global randomization in this process using the `--seed` CLI option. - # # Setting this allows you to use `--seed` to deterministically reproduce - # # test failures related to randomization by passing the same `--seed` value - # # as the one that triggered the failure. - # Kernel.srand config.seed -end +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # This setting enables warnings. It's recommended, but in some cases may + # # be too noisy due to issues in dependencies. + # config.warnings = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed +end diff --git a/src/music/genre.rb b/src/music/genre.rb index 2cc9ca4..742d8d7 100644 --- a/src/music/genre.rb +++ b/src/music/genre.rb @@ -1,27 +1,27 @@ -# Create Genre class with an association to the Item class (in a separate .rb file). -# All Genre class properties visible in the diagram should be defined and set up in the constructor method. -# Implement methods: -# add_item method in the Genre class -# should take an instance of the Item class as an input -# should add the input item to the collection of items -# should add self as a property of the item object (by using the correct setter from the item object) -# Add unit tests for all implemented methods. -# The following options should be available: -# List all genres (e.g 'Comedy', 'Thriller') -# All data should be preserved by saving collections in .json files. -# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: -# genres table -class Genre - attr_reader :items, :name, :id - - def initialize(name, id: rand(1..1000)) - @id = id - @name = name - @items = [] - end - - def add_item(item) - @items << item - item.genres = self - end -end +# Create Genre class with an association to the Item class (in a separate .rb file). +# All Genre class properties visible in the diagram should be defined and set up in the constructor method. +# Implement methods: +# add_item method in the Genre class +# should take an instance of the Item class as an input +# should add the input item to the collection of items +# should add self as a property of the item object (by using the correct setter from the item object) +# Add unit tests for all implemented methods. +# The following options should be available: +# List all genres (e.g 'Comedy', 'Thriller') +# All data should be preserved by saving collections in .json files. +# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: +# genres table +class Genre + attr_reader :items, :name, :id + + def initialize(name, id: rand(1..1000)) + @id = id + @name = name + @items = [] + end + + def add_item(item) + @items << item + item.genres = self + end +end diff --git a/src/music/music_album.rb b/src/music/music_album.rb index 6f3aad0..889c1a0 100644 --- a/src/music/music_album.rb +++ b/src/music/music_album.rb @@ -1,29 +1,29 @@ -# Create MusicAlbum class in a separate .rb file. -# All MusicAlbum class properties visible in the diagram should be defined and set up in the constructor method. -# Implement methods: -# can_be_archived?() in the MusicAlbum class -# should override the method from the parent class -# should return true if parent's method returns true AND if on_spotify equals true -# otherwise, it should return false -# Add unit tests for all implemented methods. -# The following options should be available: -# List all music albums -# Add a music album -# All data should be preserved by saving collections in .json files. -# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: -# music_albums table (add all properties and associations from the parent Item class as table columns) -require_relative '../item' -class MusicAlbum < Item - attr_accessor :name, :publish_date, :on_spotify - - def initialize(name, publish_date, on_spotify) - @id = Random.rand(1..1000) - super(publish_date, archived) - @name = name - @on_spotify = on_spotify - end - - def can_be_archived? - super && @on_spotify - end -end +# Create MusicAlbum class in a separate .rb file. +# All MusicAlbum class properties visible in the diagram should be defined and set up in the constructor method. +# Implement methods: +# can_be_archived?() in the MusicAlbum class +# should override the method from the parent class +# should return true if parent's method returns true AND if on_spotify equals true +# otherwise, it should return false +# Add unit tests for all implemented methods. +# The following options should be available: +# List all music albums +# Add a music album +# All data should be preserved by saving collections in .json files. +# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: +# music_albums table (add all properties and associations from the parent Item class as table columns) +require_relative '../item' +class MusicAlbum < Item + attr_accessor :name, :publish_date, :on_spotify + + def initialize(name, publish_date, on_spotify) + @id = Random.rand(1..1000) + super(publish_date, archived) + @name = name + @on_spotify = on_spotify + end + + def can_be_archived? + super && @on_spotify + end +end From 1aafd5c9815be4dd12b7f577ac84ef03c5977cc1 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 11:36:24 -0700 Subject: [PATCH 25/75] readmefile --- README.md | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 97022ae..2bc47c0 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,10 @@ > Describe between 1-3 key features of the application. -- **[key_feature_1]** -- **[key_feature_2]** -- **[key_feature_3]** +- **[Add Music optiion for end user]** +- **[Library Data Keeping]** +- **[Add game optiion for end users]** +- **[Add Database to store the whole data]**

(back to top)

@@ -72,9 +73,7 @@ ## 🚀 Live Demo -> Add a link to your deployed project. - -- [Live Demo Link](https://yourdeployedapplicationlink.com) +> Not applicable.

(back to top)

@@ -174,6 +173,18 @@ Example: - Twitter: [@recillahk](https://twitter.com/danmatama) - LinkedIn: [Recillah Khamala](https://www.linkedin.com/in/danielmatama-mwebesa/) +👤 **Brhanu Hailu** + +- GitHub: [@brhanuhailu](https://github.com/brhanuhailu) +- Twitter: [@tigrayfurtune](https://twitter.com/TigrayCountry) +- LinkedIn: [LinkedIn](https://www.linkedin.com/in/brhanu-hailu-85578a246/) + +👤 **Yodit Abebe** + +- GitHub: [@yodit93](https://github.com/yodit93) +- Twitter: [@@yodtwit](https://twitter.com/yodtwit) +- LinkedIn: [LinkedIn](https://www.linkedin.com/in/yodit-abebe-ayalew/) +

(back to top)

@@ -182,9 +193,9 @@ Example: > Describe 1 - 3 features you will add to the project. -- [ ] **[new_feature_1]** -- [ ] **[new_feature_2]** -- [ ] **[new_feature_3]** +- [ ] **[Add unit tests]** +- [ ] **[Create databases]** +- [ ] **[Create file for persist data]**

(back to top)

@@ -194,7 +205,7 @@ Example: Contributions, issues, and feature requests are welcome! -Feel free to check the [issues page](../../issues/). +Feel free to check the [issues page](https://github.com/brhanuhailu/ruby-capstone/issues).

(back to top)

@@ -214,7 +225,7 @@ If you like this project... > Give credit to everyone who inspired your codebase. -I would like to thank... +we would like to thank Microverse

(back to top)

@@ -238,6 +249,6 @@ I would like to thank... ## 📝 License -This project is [MIT](./LICENSE) licensed. +This project is [MIT](https://github.com/brhanuhailu/ruby-capstone/blob/dev/LICENSE) licensed.

(back to top)

\ No newline at end of file From 48c1687d80756e4d928194a3dcc26f6ec2a5375a Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 11:36:41 -0700 Subject: [PATCH 26/75] app.rb --- app.rb | 149 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 48 deletions(-) diff --git a/app.rb b/app.rb index 6687a36..fc16197 100644 --- a/app.rb +++ b/app.rb @@ -1,48 +1,101 @@ -require_relative 'book' -require_relative 'label' -require_relative './store/preserve_data' -require 'json' - -class App - def initialize - @books = [] - @labels = [] - end - - def list_books - @books.each do |book| - puts "#{book.id} - #{book.genre} - #{book.author} - #{book.published_date}" - end - end - - def list_labels - @labels.each do |label| - puts "#{label.id} - #{label.title} - #{label.color}" - end - end - - def create_book - puts 'Enter author' - author = gets.chomp - puts 'Enter published date (YYYY-MM-DD))' - published_date = gets.chomp - puts 'Enter publisher' - publisher = gets.chomp - puts 'Enter cover state' - cover_state = gets.chomp - puts 'Enter label title' - label_title = gets.chomp - puts 'Enter label color' - label_color = gets.chomp - label = Label.new(label_title, label_color) - book = Book.new(author, published_date, publisher, cover_state, label) - @books << book - @labels << label - puts 'Book created successfully' - end - - def exit_app - puts 'Thanks for using the app!' - exit - end -end +require_relative 'book' +require_relative 'label' +require_relative 'item' +require_relative 'game' +require_relative 'author' +require 'json' +require 'date' + +class App + def initialize + @books = [] + @labels = [] + @games = [] + @authors = [] + end + + def list_books + @books.each do |book| + puts "#{book.id} - #{book.genre} - #{book.author} - #{book.published_date}" + end + end + + def list_labels + @labels.each do |label| + puts "#{label.id} - #{label.title} - #{label.color}" + end + end + + def create_book + puts 'Enter author' + author = gets.chomp + puts 'Enter published date (YYYY-MM-DD))' + published_date = gets.chomp + puts 'Enter publisher' + publisher = gets.chomp + puts 'Enter cover state' + cover_state = gets.chomp + puts 'Enter label title' + label_title = gets.chomp + puts 'Enter label color' + label_color = gets.chomp + label = Label.new(label_title, label_color) + book = Book.new(author, published_date, publisher, cover_state, label) + @books << book + @labels << label + puts 'Book created successfully' + end + + def list_games + if @games.empty? + puts 'No games found in the system currently' + else + puts '=================================================================:' + puts 'List of Games:' + puts 'ID - Game Name - Last Played Date - Published Date - Multiplayer' + @games.each do |game| + puts "#{game.id} - #{game.game_name} - #{game.last_played_at} - #{game.publish_date} - #{game.multiplayer}" + puts '=================================================================:' + end + end + end + + def list_authors + if @authors.empty? + puts 'No authors found in the system currently' + else + puts '=============================================:' + puts 'List of Authors:' + puts 'ID - First Name - Last Name' + @authors.each do |author| + puts "#{author.id} - #{author.first_name} - #{author.last_name}" + puts '=============================================:' + end + end + end + + def create_games + puts 'write Name of the game' + game_name = gets.chomp + puts 'Write last played date (YYYY-MM-DD))' + last_played_at = gets.chomp + puts 'Enter published date (YYYY-MM-DD))' + publish_date = gets.chomp + puts 'Enter multiplayer' + multiplayer = gets.chomp + puts 'Enter first name' + first_name = gets.chomp + puts 'Enter last name' + last_name = gets.chomp + author = Author.new(first_name, last_name) + @authors << author + game = Game.new(game_name, last_played_at, publish_date, multiplayer) + @games << game + puts 'Game is created successfully' + end + + def exit_app + puts 'Thanks for using the app!' + exit + end +end From 8be8871fcec318bef4432c1d49bbdc7247585aed Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 11:36:57 -0700 Subject: [PATCH 27/75] authors.rb --- author.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/author.rb b/author.rb index 933a95d..473da15 100644 --- a/author.rb +++ b/author.rb @@ -4,7 +4,7 @@ class Author attr_reader :id attr_accessor :first_name, :last_name, :items - def initialize(first_name, last_name, _item) + def initialize(first_name, last_name) @id = Random.rand(1..1000) @first_name = first_name @last_name = last_name From 9395d1e9b9cb8274151136a66ab433de73cef9d4 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 11:37:12 -0700 Subject: [PATCH 28/75] game.rb --- game.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/game.rb b/game.rb index 3e443c3..77f8a68 100644 --- a/game.rb +++ b/game.rb @@ -1,10 +1,16 @@ +require_relative 'item' +require 'date' + class Game < Item - attr_accessor :multiplayer, :last_played_date + attr_accessor :id, :game_name, :multiplayer, :last_played_at, :publish_date - def initialize(genre, author, published_date, multiplayer, last_played_date) - super(genre, author, label, published_date) + def initialize(game_name, last_played_at, publish_date, multiplayer) + super(nil, nil, nil, publish_date) + @id = id || Random.rand(1..1000) + @game_name = game_name @multiplayer = multiplayer - @last_played_date = last_played_date + @last_played_at = last_played_at + @publish_date = Date.parse(publish_date) end def move_to_archive @@ -14,7 +20,7 @@ def move_to_archive private def can_be_archived? - age_in_years = Time.now.year - @last_played_date.year + age_in_years = Time.now.year - @last_played_at.year age_in_years >= 10 end end From b01c1f1ec4236fc094d7b0c9224895b553d72d7f Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 11:43:43 -0700 Subject: [PATCH 29/75] game --- game.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.rb b/game.rb index 77f8a68..c0efdeb 100644 --- a/game.rb +++ b/game.rb @@ -21,6 +21,6 @@ def move_to_archive def can_be_archived? age_in_years = Time.now.year - @last_played_at.year - age_in_years >= 10 + age_in_years >= 2 end end From bd21bd0e211c42c24b9148767d41620e832defe0 Mon Sep 17 00:00:00 2001 From: Brhanu Hailu Date: Tue, 30 May 2023 12:39:54 -0700 Subject: [PATCH 30/75] Update app.rb --- app.rb | 104 +++++++++++++++------------------------------------------ 1 file changed, 27 insertions(+), 77 deletions(-) diff --git a/app.rb b/app.rb index 90bedb9..634f23c 100644 --- a/app.rb +++ b/app.rb @@ -1,29 +1,30 @@ - require_relative 'book' require_relative 'label' require_relative 'item' require_relative 'game' +require_relative './store/preserve_data' require_relative 'author' require 'json' require 'date' class App def initialize - @books = [] - @labels = [] + @store = PreserveData.new + @books = File.empty?('./store/books.json') ? [] : @store.load_data('./store/books.json') + @labels = File.empty?('./store/labels.json') ? [] : @store.load_data('./store/labels.json') @games = [] @authors = [] end def list_books @books.each do |book| - puts "#{book.id} - #{book.genre} - #{book.author} - #{book.published_date}" + puts "#{book['id']} - #{book['author']} - #{book['published_date']}" end end def list_labels @labels.each do |label| - puts "#{label.id} - #{label.title} - #{label.color}" + puts "#{label['id']} - #{label['title']} - #{label['color']}" end end @@ -40,13 +41,32 @@ def create_book label_title = gets.chomp puts 'Enter label color' label_color = gets.chomp - label = Label.new(label_title, label_color) - book = Book.new(author, published_date, publisher, cover_state, label) + label = create_label(label_title, label_color) + book = create_book_object(author, published_date, publisher, cover_state, label) @books << book @labels << label + @store.save_data(@books, './store/books.json') + @store.save_data(@labels, './store/labels.json') puts 'Book created successfully' end + def create_label(title, color) + label = Label.new(title, color) + { 'id' => label.id, 'title' => label.title, 'color' => label.color } + end + + def create_book_object(author, published_date, publisher, cover_state, label) + book = Book.new(author, published_date, publisher, cover_state, label) + { + 'id' => book.id, + 'author' => book.author, + 'published_date' => book.published_date, + 'publisher' => book.publisher, + 'cover_state' => book.cover_state, + 'label' => book.label + } + end + def list_games if @games.empty? puts 'No games found in the system currently' @@ -100,73 +120,3 @@ def exit_app exit end end - -require_relative 'book' -require_relative 'label' -require_relative './store/preserve_data' -require 'json' - -class App - def initialize - @store = PreserveData.new - @books = File.empty?('./store/books.json') ? [] : @store.load_data('./store/books.json') - @labels = File.empty?('./store/labels.json') ? [] : @store.load_data('./store/labels.json') - end - - def list_books - @books.each do |book| - puts "#{book['id']} - #{book['author']} - #{book['published_date']}" - end - end - - def list_labels - @labels.each do |label| - puts "#{label['id']} - #{label['title']} - #{label['color']}" - end - end - - def create_book - puts 'Enter author' - author = gets.chomp - puts 'Enter published date (YYYY-MM-DD))' - published_date = gets.chomp - puts 'Enter publisher' - publisher = gets.chomp - puts 'Enter cover state' - cover_state = gets.chomp - puts 'Enter label title' - label_title = gets.chomp - puts 'Enter label color' - label_color = gets.chomp - label = create_label(label_title, label_color) - book = create_book_object(author, published_date, publisher, cover_state, label) - @books << book - @labels << label - @store.save_data(@books, './store/books.json') - @store.save_data(@labels, './store/labels.json') - puts 'Book created successfully' - end - - def create_label(title, color) - label = Label.new(title, color) - { 'id' => label.id, 'title' => label.title, 'color' => label.color } - end - - def create_book_object(author, published_date, publisher, cover_state, label) - book = Book.new(author, published_date, publisher, cover_state, label) - { - 'id' => book.id, - 'author' => book.author, - 'published_date' => book.published_date, - 'publisher' => book.publisher, - 'cover_state' => book.cover_state, - 'label' => book.label - } - end - - def exit_app - puts 'Thanks for using the app!' - exit - end -end - From ad65b595d5347ecdd557e5dce365e3169cf69286 Mon Sep 17 00:00:00 2001 From: Brhanu Hailu Date: Tue, 30 May 2023 12:41:05 -0700 Subject: [PATCH 31/75] Update author.rb --- author.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/author.rb b/author.rb index 2a1ff66..473da15 100644 --- a/author.rb +++ b/author.rb @@ -1,4 +1,3 @@ - require_relative 'item' class Author From 7b5fbedd69ea5a5e31474e582227bfaa7d24c091 Mon Sep 17 00:00:00 2001 From: Brhanu Hailu Date: Tue, 30 May 2023 12:43:29 -0700 Subject: [PATCH 32/75] Update game.rb --- game.rb | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/game.rb b/game.rb index d9c0584..c0efdeb 100644 --- a/game.rb +++ b/game.rb @@ -1,4 +1,3 @@ - require_relative 'item' require 'date' @@ -25,24 +24,3 @@ def can_be_archived? age_in_years >= 2 end end - -class Game < Item - attr_accessor :multiplayer, :last_played_date - - def initialize(genre, author, published_date, multiplayer, last_played_date) - super(genre, author, label, published_date) - @multiplayer = multiplayer - @last_played_date = last_played_date - end - - def move_to_archive - @archived = true if can_be_archived? - end - - private - - def can_be_archived? - age_in_years = Time.now.year - @last_played_date.year - age_in_years >= 10 - end -end From 3a97de877dd550ce4b25edede3b88df95c40e0ec Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 14:11:17 -0700 Subject: [PATCH 33/75] app.rb --- app.rb | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/app.rb b/app.rb index 634f23c..51dad3a 100644 --- a/app.rb +++ b/app.rb @@ -12,8 +12,8 @@ def initialize @store = PreserveData.new @books = File.empty?('./store/books.json') ? [] : @store.load_data('./store/books.json') @labels = File.empty?('./store/labels.json') ? [] : @store.load_data('./store/labels.json') - @games = [] - @authors = [] + @games = File.empty?('./store/games.json') ? [] : @store.load_data('./store/games.json') + @authors = File.empty?('./store/authors.json') ? [] : @store.load_data('./store/authors.json') end def list_books @@ -73,11 +73,12 @@ def list_games else puts '=================================================================:' puts 'List of Games:' + puts '=================================================================:' puts 'ID - Game Name - Last Played Date - Published Date - Multiplayer' @games.each do |game| - puts "#{game.id} - #{game.game_name} - #{game.last_played_at} - #{game.publish_date} - #{game.multiplayer}" - puts '=================================================================:' + puts "#{game['id']} - #{game['game_name']} - #{game['last_played_at']} - #{game['publish_date']} - #{game['multiplayer']}" end + puts '=================================================================:' end end @@ -87,11 +88,12 @@ def list_authors else puts '=============================================:' puts 'List of Authors:' + puts '=============================================:' puts 'ID - First Name - Last Name' @authors.each do |author| - puts "#{author.id} - #{author.first_name} - #{author.last_name}" - puts '=============================================:' + puts "#{author['id']} - #{author['first_name']} - #{author['last_name']}" end + puts '=============================================:' end end @@ -108,13 +110,35 @@ def create_games first_name = gets.chomp puts 'Enter last name' last_name = gets.chomp - author = Author.new(first_name, last_name) + author = create_author(first_name, last_name) @authors << author - game = Game.new(game_name, last_played_at, publish_date, multiplayer) + @store.save_data(@authors, './store/authors.json') + game = create_game_object(game_name, last_played_at, publish_date, multiplayer) @games << game + @store.save_data(@games, './store/games.json') puts 'Game is created successfully' end + def create_author (first_name, last_name) + author = Author.new(first_name, last_name) + { + 'id' => author.id, + 'first_name' => author.first_name, + 'last_name' => author.last_name + } + end + + def create_game_object(game_name, last_played_at, publish_date, multiplayer) + game = Game.new(game_name, last_played_at, publish_date, multiplayer) + { + 'id' => game.id, + 'game_name' => game.game_name, + 'last_played_at' => game.last_played_at, + 'publish_date' => game.publish_date, + 'multiplayer' => game.multiplayer + } + end + def exit_app puts 'Thanks for using the app!' exit From f797dee9fb177d0574310b3fa5b6167c98c96f68 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 14:11:49 -0700 Subject: [PATCH 34/75] authors.json --- store/authors.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 store/authors.json diff --git a/store/authors.json b/store/authors.json new file mode 100644 index 0000000..7858658 --- /dev/null +++ b/store/authors.json @@ -0,0 +1,17 @@ +[ + { + "id": 180, + "first_name": "bvcx", + "last_name": "nbcc" + }, + { + "id": 631, + "first_name": "Brhanu", + "last_name": "Hailu" + }, + { + "id": 483, + "first_name": "marki", + "last_name": "msess" + } +] \ No newline at end of file From 64747014dd4d49b1b804e8ada5c840430c372ba6 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 14:12:20 -0700 Subject: [PATCH 35/75] game.json --- store/games.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 store/games.json diff --git a/store/games.json b/store/games.json new file mode 100644 index 0000000..31ed9fc --- /dev/null +++ b/store/games.json @@ -0,0 +1,23 @@ +[ + { + "id": 146, + "game_name": "jhkjkk", + "last_played_at": "2023-5-2", + "publish_date": "2022-05-03", + "multiplayer": "jhhjhhj" + }, + { + "id": 395, + "game_name": "valleyball", + "last_played_at": "2023-6-2", + "publish_date": "2022-05-03", + "multiplayer": "vlc" + }, + { + "id": 601, + "game_name": "hwrhawi", + "last_played_at": "1-2-2023", + "publish_date": "2023-06-02", + "multiplayer": "mcccccc" + } +] \ No newline at end of file From 66e1c995e2c04736a8d5665b2dc57514e6a891dd Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Tue, 30 May 2023 14:20:55 -0700 Subject: [PATCH 36/75] fix linters --- .rubocop.yml | 2 +- app.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dc7cd33..400e887 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,7 +8,7 @@ AllCops: DisplayCopNames: true Layout/LineLength: - Max: 120 + Max: 130 Metrics/MethodLength: Max: 25 Metrics/AbcSize: diff --git a/app.rb b/app.rb index 51dad3a..82a1428 100644 --- a/app.rb +++ b/app.rb @@ -119,7 +119,7 @@ def create_games puts 'Game is created successfully' end - def create_author (first_name, last_name) + def create_author(first_name, last_name) author = Author.new(first_name, last_name) { 'id' => author.id, From d26d9265969ad2b28f5199d4f0d531e675e63737 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 11:01:23 +0300 Subject: [PATCH 37/75] Add unit tests for book class --- spec/book_spec.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 spec/book_spec.rb diff --git a/spec/book_spec.rb b/spec/book_spec.rb new file mode 100644 index 0000000..c6e67ad --- /dev/null +++ b/spec/book_spec.rb @@ -0,0 +1,44 @@ +require_relative './spec_helper' +describe Book do + before(:all) do + label = Label.new('Fiction', 'blue') + @book = Book.new('author', '2020-01-01', 'publisher', 'good', label) + end + + describe '#initialize' do + it 'creates a new Book instance' do + expect(@book).to be_an_instance_of Book + end + + it 'the author of the book should be "author"' do + expect(@book.author).to eq('author') + end + + it 'the publication date of the book should be "2020-01-01"' do + expect(@book.published_date).to eq('2020-01-01') + end + + it 'the publisher of the book should be "publisher"' do + expect(@book.publisher).to eq('publisher') + end + + it 'the cover state of the book should be "good"' do + expect(@book.cover_state).to eq('good') + end + + it 'the label of the book should be a Label instance' do + expect(@book.label).to be_kind_of Label + end + end + + describe '#can_be_archived?' do + it 'should return true for less than 10 years' do + expect(@book.can_be_archived?).to eq(false) + end + + it 'should return false for more than 10 years' do + @book.published_date = '2010-01-01' + expect(@book.can_be_archived?).to eq(true) + end + end +end From ee1eb5913f47afd5859bf7434495c205b1ac20a1 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 11:01:51 +0300 Subject: [PATCH 38/75] Add unit tests for label class --- spec/label_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/label_spec.rb diff --git a/spec/label_spec.rb b/spec/label_spec.rb new file mode 100644 index 0000000..b46c754 --- /dev/null +++ b/spec/label_spec.rb @@ -0,0 +1,29 @@ +require_relative './spec_helper' + +describe Label do + before(:all) do + @label = Label.new('Fiction', 'blue') + end + + describe '#initialize' do + it 'creates a new Label instance' do + expect(@label).to be_an_instance_of Label + end + + it 'the title of the label should be "Fiction"' do + expect(@label.title).to eq('Fiction') + end + + it 'the color of the label should be "blue"' do + expect(@label.color).to eq('blue') + end + end + + describe '#add_item' do + it 'should add an item to the label' do + book = Book.new('author', '2020-01-01', 'publisher', 'good', nil) + @label.add_item(book) + expect(@label.items).to include(book) + end + end +end From 30f3193158a2d64f1577debc091d5d5cbbef2b61 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 11:02:48 +0300 Subject: [PATCH 39/75] Import book and label class file to helper file --- spec/spec_helper.rb | 98 +-------------------------------------------- 1 file changed, 2 insertions(+), 96 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0f4e1b6..25d7aa3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,96 +1,2 @@ -# This file was generated by the `rspec --init` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration -RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. - config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end - - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. - config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. - mocks.verify_partial_doubles = true - end - - # This option will default to `:apply_to_host_groups` in RSpec 4 (and will - # have no way to turn it off -- the option exists only for backwards - # compatibility in RSpec 3). It causes shared context metadata to be - # inherited by the metadata hash of host groups and examples, rather than - # triggering implicit auto-inclusion in groups with matching metadata. - config.shared_context_metadata_behavior = :apply_to_host_groups - - # The settings below are suggested to provide a good initial experience - # with RSpec, but feel free to customize to your heart's content. - # # This allows you to limit a spec run to individual examples or groups - # # you care about by tagging them with `:focus` metadata. When nothing - # # is tagged with `:focus`, all examples get run. RSpec also provides - # # aliases for `it`, `describe`, and `context` that include `:focus` - # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - # config.filter_run_when_matching :focus - # - # # Allows RSpec to persist some state between runs in order to support - # # the `--only-failures` and `--next-failure` CLI options. We recommend - # # you configure your source control system to ignore this file. - # config.example_status_persistence_file_path = "spec/examples.txt" - # - # # Limits the available syntax to the non-monkey patched syntax that is - # # recommended. For more details, see: - # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode - # config.disable_monkey_patching! - # - # # This setting enables warnings. It's recommended, but in some cases may - # # be too noisy due to issues in dependencies. - # config.warnings = true - # - # # Many RSpec users commonly either run the entire suite or an individual - # # file, and it's useful to allow more verbose output when running an - # # individual spec file. - # if config.files_to_run.one? - # # Use the documentation formatter for detailed output, - # # unless a formatter has already been configured - # # (e.g. via a command-line flag). - # config.default_formatter = "doc" - # end - # - # # Print the 10 slowest examples and example groups at the - # # end of the spec run, to help surface which specs are running - # # particularly slow. - # config.profile_examples = 10 - # - # # Run specs in random order to surface order dependencies. If you find an - # # order dependency and want to debug it, you can fix the order by providing - # # the seed, which is printed after each run. - # # --seed 1234 - # config.order = :random - # - # # Seed global randomization in this process using the `--seed` CLI option. - # # Setting this allows you to use `--seed` to deterministically reproduce - # # test failures related to randomization by passing the same `--seed` value - # # as the one that triggered the failure. - # Kernel.srand config.seed -end +require_relative '../book' +require_relative '../label' From 79de1943395a32d8fd8a966c6917c2925befdfb6 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 11:05:01 +0300 Subject: [PATCH 40/75] Update the published_date string to be date object --- item.rb | 59 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/item.rb b/item.rb index 91cb95c..36031e0 100644 --- a/item.rb +++ b/item.rb @@ -1,29 +1,30 @@ -require_relative 'label' - -class Item - attr_reader :id, :archived, :label - attr_accessor :genre, :author, :published_date - - def initialize(genre, author, published_date, label = nil) - @id = Random.rand(1..1000) - @genre = genre - @author = author - @label = label - @published_date = published_date - @archived = false - end - - def can_be_archived? - age_in_years = Time.now.year - @published_date.year - age_in_years >= 10 - end - - def move_to_archive - @archived = true if can_be_archived? - end - - def label=(label) - @label = label - label.add_item(self) - end -end +require 'date' +require_relative 'label' + +class Item + attr_reader :id, :archived, :label + attr_accessor :genre, :author, :published_date + + def initialize(genre, author, published_date, label = nil) + @id = Random.rand(1..1000) + @genre = genre + @author = author + @label = label + @published_date = published_date + @archived = false + end + + def can_be_archived? + age_in_years = Time.now.year - Date.parse(@published_date).year + age_in_years >= 10 + end + + def move_to_archive + @archived = true if can_be_archived? + end + + def label=(label) + @label = label + label.add_item(self) + end +end From bd4909f57aa8012bc9782e14d6264ce0c27cf05d Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 01:39:07 -0700 Subject: [PATCH 41/75] app.rb --- app.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.rb b/app.rb index 82a1428..0c92a2d 100644 --- a/app.rb +++ b/app.rb @@ -104,8 +104,8 @@ def create_games last_played_at = gets.chomp puts 'Enter published date (YYYY-MM-DD))' publish_date = gets.chomp - puts 'Enter multiplayer' - multiplayer = gets.chomp + puts 'Enter multiplayer (yes/no)' + multiplayer = gets.chomp.downcase == 'yes' puts 'Enter first name' first_name = gets.chomp puts 'Enter last name' From 73760bff59acedc87f72bdaaaabc4d9cfc682067 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 01:40:07 -0700 Subject: [PATCH 42/75] spec helper class --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 25d7aa3..a2d8063 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,5 @@ require_relative '../book' require_relative '../label' +require_relative '../game' +require_relative '../author' +require_relative '../item' From e7f437098cb9563b965e45ca2eee4a57307e4824 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 01:41:26 -0700 Subject: [PATCH 43/75] authors modification --- store/authors.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/store/authors.json b/store/authors.json index 7858658..cbe4575 100644 --- a/store/authors.json +++ b/store/authors.json @@ -13,5 +13,10 @@ "id": 483, "first_name": "marki", "last_name": "msess" + }, + { + "id": 839, + "first_name": "Abebe", + "last_name": "kebede" } ] \ No newline at end of file From 58646843729a722f542008597b484780bcdab1e3 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 01:41:56 -0700 Subject: [PATCH 44/75] game spec.rb --- store/games.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/store/games.json b/store/games.json index 31ed9fc..9a4bedc 100644 --- a/store/games.json +++ b/store/games.json @@ -19,5 +19,12 @@ "last_played_at": "1-2-2023", "publish_date": "2023-06-02", "multiplayer": "mcccccc" + }, + { + "id": 59, + "game_name": "merseir", + "last_played_at": "1-2-2023", + "publish_date": "2023-02-02", + "multiplayer": true } ] \ No newline at end of file From f29b33ee11a397864b47f826c60307eb0f10bfbf Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 01:42:30 -0700 Subject: [PATCH 45/75] author unit test class --- spec/author_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/author_spec.rb diff --git a/spec/author_spec.rb b/spec/author_spec.rb new file mode 100644 index 0000000..a4a6b62 --- /dev/null +++ b/spec/author_spec.rb @@ -0,0 +1,27 @@ +require_relative '../author' +require_relative '../item' + +RSpec.describe Author do + describe '#add_author' do + let(:author) { Author.new('John', 'Doe') } + let(:item) { Item.new('Example Item') } + + it 'adds an item to the author' do + author.add_author(item) + expect(author.items).to include(item) + end + + it 'sets the author of the item to the current author' do + author.add_author(item) + expect(item.author).to eq(author) + end + end + + describe '#full_name' do + let(:author) { Author.new('John', 'Doe') } + + it 'returns the full name of the author' do + expect(author.full_name).to eq('John Doe') + end + end +end From 2525ba214f25a418e1c05e2516a6ff8d496932a4 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 01:43:00 -0700 Subject: [PATCH 46/75] game unit test class --- spec/game_spec.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 spec/game_spec.rb diff --git a/spec/game_spec.rb b/spec/game_spec.rb new file mode 100644 index 0000000..58da9ef --- /dev/null +++ b/spec/game_spec.rb @@ -0,0 +1,59 @@ +RSpec.describe Game do + let(:game) { Game.new('Game Name', '2022-01-01', '2022-01-01', 'Yes') } + + describe '#initialize' do + it 'sets the game_name' do + expect(game.game_name).to eq('Game Name') + end + + it 'sets the multiplayer' do + expect(game.multiplayer).to eq('Yes') + end + + it 'sets the last_played_at' do + expect(game.last_played_at).to eq('2022-01-01') + end + + it 'sets the publish_date' do + expect(game.publish_date).to eq(Date.parse('2022-01-01')) + end + end + + describe '#move_to_archive' do + context 'when the game is older than 2 years' do + let(:game) { Game.new('Game Name', '2020-01-01', '2022-01-01', 'Yes') } + + it 'moves the game to archive' do + game.move_to_archive + expect(game.archived).to be true + end + end + + context 'when the game is newer than 2 years' do + let(:game) { Game.new('Game Name', '2022-01-01', '2022-01-01', 'Yes') } + + it 'does not move the game to archive' do + game.move_to_archive + expect(game.archived).to be nil + end + end + end + + describe '#can_be_archived?' do + context 'when the game is older than 2 years' do + let(:game) { Game.new('Game Name', '2020-01-01', '2022-01-01', 'Yes') } + + it 'returns true' do + expect(game.send(:can_be_archived?)).to be true + end + end + + context 'when the game is newer than 2 years' do + let(:game) { Game.new('Game Name', '2022-01-01', '2022-01-01', 'Yes') } + + it 'returns false' do + expect(game.send(:can_be_archived?)).to be false + end + end + end +end From 4647e4ac68d9d4f735929aa955efb4837d3d3eff Mon Sep 17 00:00:00 2001 From: daniel matama Date: Wed, 31 May 2023 12:35:22 +0300 Subject: [PATCH 47/75] create json --- src/json_files/genres.json | 10 ++++++++++ src/json_files/music_albums.json | 12 ++++++++++++ src/music/schema_2.sql | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/music/schema_2.sql diff --git a/src/json_files/genres.json b/src/json_files/genres.json index e69de29..2a4237f 100644 --- a/src/json_files/genres.json +++ b/src/json_files/genres.json @@ -0,0 +1,10 @@ +[ + { + "genre_id" : 77, + "genre_name" : "yyyy" + }, + { + "genre_id" : 570, + "genre_name" : "tttt" + } + ] \ No newline at end of file diff --git a/src/json_files/music_albums.json b/src/json_files/music_albums.json index e69de29..2f611fb 100644 --- a/src/json_files/music_albums.json +++ b/src/json_files/music_albums.json @@ -0,0 +1,12 @@ +[ + { + "music_id" : 45, + "music_name" : "www", + "music_on_spotify" : true + }, + { + "music_id" : 53, + "music_name" : "8", + "music_on_spotify" : true + } + ] \ No newline at end of file diff --git a/src/music/schema_2.sql b/src/music/schema_2.sql new file mode 100644 index 0000000..86805c8 --- /dev/null +++ b/src/music/schema_2.sql @@ -0,0 +1,28 @@ +-- create genre table +CREATE TABLE Genre( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + name VARCHAR(60) NOT NULL +); + +-- create item table + +CREATE TABLE item( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + genre_id INT, + author_id INT, + source_id INT, + label_id INT, + publish_date Date, + archived BOOLEAN, + FOREIGN KEY(genre_id) REFERENCES Genre(id) ON UPDATE CASCADE, + FOREIGN KEY(author_id) REFERENCES Author(id) ON UPDATE CASCADE, + FOREIGN KEY(source_id) REFERENCES Source(id) ON UPDATE CASCADE, + FOREIGN KEY(label_id) REFERENCES Label(id) ON UPDATE CASCADE +); + +-- create music_album table +CREATE TABLE MusicAlbum( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + on_spotify BOOLEAN NOT NULL, + FOREIGN KEY(id) REFERENCES item(id) ON UPDATE CASCADE +); \ No newline at end of file From bd36b0de4c43fe4aef49dd08084c3cc116ba4d09 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 12:36:37 +0300 Subject: [PATCH 48/75] Create catalog database --- Database/schema.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Database/schema.sql diff --git a/Database/schema.sql b/Database/schema.sql new file mode 100644 index 0000000..541aa67 --- /dev/null +++ b/Database/schema.sql @@ -0,0 +1,3 @@ +-- create catalog of my things database +CREATE DATABASE catalog; + From 6c6f8fa884dbb0102004faab8a6bf80482f2cd3b Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 12:37:28 +0300 Subject: [PATCH 49/75] Create label table --- Database/schema.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Database/schema.sql b/Database/schema.sql index 541aa67..0195ef9 100644 --- a/Database/schema.sql +++ b/Database/schema.sql @@ -1,3 +1,10 @@ -- create catalog of my things database CREATE DATABASE catalog; +-- create label table + +CREATE TABLE label ( + id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + title VARCHAR(100) NOT NULL, + color VARCHAR(100) NOT NULL +); From 39b1d7f5f11dcd3ede034bbe25618c2d06ad777c Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 12:37:57 +0300 Subject: [PATCH 50/75] Create book table --- Database/schema.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Database/schema.sql b/Database/schema.sql index 0195ef9..25ba846 100644 --- a/Database/schema.sql +++ b/Database/schema.sql @@ -8,3 +8,16 @@ CREATE TABLE label ( title VARCHAR(100) NOT NULL, color VARCHAR(100) NOT NULL ); + +-- create book table +CREATE TABLE book ( + id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + author TEXT, + published_date DATE, + publisher TEXT, + archived BOOLEAN NOT NULL DEFAULT FALSE, + cover_state VARCHAR(5), + label_id int REFERENCES label(id), + genre TEXT +); + From 3aef1d384d301bee50c48f217c683828a40c32c4 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Wed, 31 May 2023 12:44:22 +0300 Subject: [PATCH 51/75] Update tests.yml file --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed1fedd..f44b191 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,15 +5,15 @@ on: pull_request jobs: rspec: name: RSpec - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-ruby@v1 with: - ruby-version: 2.6.x + ruby-version: 3.1.x - name: Setup RSpec run: | - [ -f Gemfile ] && bundle --deployment - gem install --no-document rspec:'~>3.0' + [ -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 From 270d1f9ffc8746e27b4ade3e052ab128c19c2ff0 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 02:50:34 -0700 Subject: [PATCH 52/75] test --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed1fedd..f44b191 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,15 +5,15 @@ on: pull_request jobs: rspec: name: RSpec - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-ruby@v1 with: - ruby-version: 2.6.x + ruby-version: 3.1.x - name: Setup RSpec run: | - [ -f Gemfile ] && bundle --deployment - gem install --no-document rspec:'~>3.0' + [ -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 From fd1c69e3b4435e3b2f3fba80d09359b401c1cd20 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 03:18:01 -0700 Subject: [PATCH 53/75] test fix --- game.rb | 2 +- spec/author_spec.rb | 6 ++---- store/authors.json | 5 +++++ store/games.json | 7 +++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/game.rb b/game.rb index c0efdeb..19555ea 100644 --- a/game.rb +++ b/game.rb @@ -9,7 +9,7 @@ def initialize(game_name, last_played_at, publish_date, multiplayer) @id = id || Random.rand(1..1000) @game_name = game_name @multiplayer = multiplayer - @last_played_at = last_played_at + @last_played_at = Date.parse(last_played_at) @publish_date = Date.parse(publish_date) end diff --git a/spec/author_spec.rb b/spec/author_spec.rb index a4a6b62..ec7def1 100644 --- a/spec/author_spec.rb +++ b/spec/author_spec.rb @@ -1,10 +1,8 @@ -require_relative '../author' -require_relative '../item' RSpec.describe Author do describe '#add_author' do let(:author) { Author.new('John', 'Doe') } - let(:item) { Item.new('Example Item') } + let(:item) { Item.new('gameone', 'hall', '2022-1-2', nil) } it 'adds an item to the author' do author.add_author(item) @@ -24,4 +22,4 @@ expect(author.full_name).to eq('John Doe') end end -end +end \ No newline at end of file diff --git a/store/authors.json b/store/authors.json index cbe4575..84913c2 100644 --- a/store/authors.json +++ b/store/authors.json @@ -18,5 +18,10 @@ "id": 839, "first_name": "Abebe", "last_name": "kebede" + }, + { + "id": 868, + "first_name": "kebede", + "last_name": "melaku" } ] \ No newline at end of file diff --git a/store/games.json b/store/games.json index 9a4bedc..d72c13c 100644 --- a/store/games.json +++ b/store/games.json @@ -26,5 +26,12 @@ "last_played_at": "1-2-2023", "publish_date": "2023-02-02", "multiplayer": true + }, + { + "id": 567, + "game_name": "abeb", + "last_played_at": "2023-02-05", + "publish_date": "2022-04-01", + "multiplayer": true } ] \ No newline at end of file From 38f4647d1eb19b58ff5e88adf1e147c9434a627a Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 03:19:54 -0700 Subject: [PATCH 54/75] rubocop --- spec/author_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/author_spec.rb b/spec/author_spec.rb index ec7def1..2522f53 100644 --- a/spec/author_spec.rb +++ b/spec/author_spec.rb @@ -1,4 +1,3 @@ - RSpec.describe Author do describe '#add_author' do let(:author) { Author.new('John', 'Doe') } @@ -22,4 +21,4 @@ expect(author.full_name).to eq('John Doe') end end -end \ No newline at end of file +end From 5497640168056b847d9a3ec719b42c8d0d9cbf6d Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 03:26:42 -0700 Subject: [PATCH 55/75] fixed some tests --- spec/game_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 58da9ef..62e691b 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -11,7 +11,7 @@ end it 'sets the last_played_at' do - expect(game.last_played_at).to eq('2022-01-01') + expect(game.last_played_at).to eq(Date.parse('2022-01-01')) end it 'sets the publish_date' do @@ -34,7 +34,7 @@ it 'does not move the game to archive' do game.move_to_archive - expect(game.archived).to be nil + expect(game.archived).to be false end end end From 1e7c7aa63e6e30e2f2f8624f69cdcb23ee319ecc Mon Sep 17 00:00:00 2001 From: daniel matama Date: Wed, 31 May 2023 13:43:41 +0300 Subject: [PATCH 56/75] Fix linters --- app.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app.rb b/app.rb index 3d2b2d2..aea5bb0 100644 --- a/app.rb +++ b/app.rb @@ -205,7 +205,6 @@ def store_genre_data end update_data(array, './store/genres.json') end -end def exit_app puts 'Thanks for using the app!' From d22c03fd79be0609504d8a5c8bee4769cbb1ebc7 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Wed, 31 May 2023 16:11:07 +0300 Subject: [PATCH 57/75] Update app to solve linter errors --- app.rb | 79 +++++++----------------------------------------------- handler.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++ storage.rb | 22 +++++++++++++++ store.rb | 14 ++++++++++ 4 files changed, 115 insertions(+), 69 deletions(-) create mode 100644 handler.rb create mode 100644 storage.rb create mode 100644 store.rb diff --git a/app.rb b/app.rb index aea5bb0..72b8222 100644 --- a/app.rb +++ b/app.rb @@ -8,16 +8,20 @@ require 'date' require_relative './src/genre' require_relative './src/music_album' +require_relative './handler' -class App +class App < Handler def initialize + super + @genres = [] + @music_albums = [] + + # @storage = Storage.new(self) @store = PreserveData.new @books = File.empty?('./store/books.json') ? [] : @store.load_data('./store/books.json') @labels = File.empty?('./store/labels.json') ? [] : @store.load_data('./store/labels.json') @games = File.empty?('./store/games.json') ? [] : @store.load_data('./store/games.json') @authors = File.empty?('./store/authors.json') ? [] : @store.load_data('./store/authors.json') - @genre = File.empty?('./store/genre.json') ? [] : @store.load_data('./store/genre.json') - @music_albums = File.empty?('./store/music_albums.json') ? [] : @store.load_data('./store/music_albums.json') end def list_books @@ -94,7 +98,7 @@ def list_authors puts 'List of Authors:' puts '=============================================:' puts 'ID - First Name - Last Name' - @authors.each do |author| + authors.each do |author| puts "#{author['id']} - #{author['first_name']} - #{author['last_name']}" end puts '=============================================:' @@ -115,8 +119,8 @@ def create_games puts 'Enter last name' last_name = gets.chomp author = create_author(first_name, last_name) - @authors << author - @store.save_data(@authors, './store/authors.json') + authors << author + @store.save_data(authors, './store/authors.json') game = create_game_object(game_name, last_played_at, publish_date, multiplayer) @games << game @store.save_data(@games, './store/games.json') @@ -143,69 +147,6 @@ def create_game_object(game_name, last_played_at, publish_date, multiplayer) } end - def add_music_album - puts 'Album name: ' - name = gets.chomp - puts 'Genre: ' - genre_name = gets.chomp - @genres.push(Genre.new(genre_name)) - store_genre_data - - puts 'Date of publish [Enter date in format (yyyy-mm-dd)]' - publish_date = gets.chomp - - puts 'Is it available on Spotify? Y/N' - on_spotify = gets.chomp.downcase - case on_spotify - when 'y' - @music_albums.push(MusicAlbum.new(name, publish_date, true)) - when 'n' - @music_albums.push(MusicAlbum.new(name, publish_date, false)) - end - puts 'Music album created' - store_music_data - end - - def albums - music_data = get_data('./store/music_albums.json') - puts 'No music found' if music_data.empty? - music_data.each do |music_album| - puts "Album_name: #{music_album['music_name']} | On_spotify: #{music_album['music_on_spotify']}" - end - end - - def genres - data = get_data('./store/genres.json') - puts 'No genre found' if data.empty? - data.each do |genre| - puts "Genre name: #{genre['genre_name']}" - end - end - - def store_music_data - array = [] - @music_albums.each do |music| - array << { - music_id: music.id, - music_name: music.name, - music_on_spotify: music.on_spotify - - } - end - update_data(array, './store/music_albums.json') - end - - def store_genre_data - array = [] - @genres.each do |genre| - array << { - genre_id: genre.id, - genre_name: genre.name - } - end - update_data(array, './store/genres.json') - end - def exit_app puts 'Thanks for using the app!' exit diff --git a/handler.rb b/handler.rb new file mode 100644 index 0000000..7431e50 --- /dev/null +++ b/handler.rb @@ -0,0 +1,69 @@ +require_relative './store' + +class Handler + include JsonStorage + include Storage + + def add_music_album + puts 'Album name: ' + name = gets.chomp + puts 'Genre: ' + genre_name = gets.chomp + @genres.push(Genre.new(genre_name)) + store_genre_data + + puts 'Date of publish [Enter date in format (yyyy-mm-dd)]' + publish_date = gets.chomp + + puts 'Is it available on Spotify? Y/N' + on_spotify = gets.chomp.downcase + case on_spotify + when 'y' + @music_albums.push(MusicAlbum.new(name, publish_date, true)) + when 'n' + @music_albums.push(MusicAlbum.new(name, publish_date, false)) + end + puts 'Music album created' + store_music_data + end + + def albums + music_data = get_data('./store/music_albums.json') + puts 'No music found' if music_data.empty? + music_data.each do |music_album| + puts "Album_name: #{music_album['music_name']} | On_spotify: #{music_album['music_on_spotify']}" + end + end + + def genres + data = get_data('./store/genres.json') + puts 'No genre found' if data.empty? + data.each do |genre| + puts "Genre name: #{genre['genre_name']}" + end + end + + def store_music_data + array = [] + @music_albums.each do |music| + array << { + music_id: music.id, + music_name: music.name, + music_on_spotify: music.on_spotify + + } + end + update_data(array, './store/music_albums.json') + end + + def store_genre_data + array = [] + @genres.each do |genre| + array << { + genre_id: genre.id, + genre_name: genre.name + } + end + update_data(array, './store/genres.json') + end +end diff --git a/storage.rb b/storage.rb new file mode 100644 index 0000000..072d0a6 --- /dev/null +++ b/storage.rb @@ -0,0 +1,22 @@ +require 'json' + +module JsonStorage + def update_data(array, file_path) + opts = { + array_nl: "\n", + object_nl: "\n", + indent: ' ', + space_before: ' ', + space: ' ' + } + json = JSON.generate(array, opts) + File.write(file_path, json) + end + + def get_data(file_path) + return [] unless File.exist?(file_path) + + file = File.read(file_path) + JSON.parse(file) + end +end diff --git a/store.rb b/store.rb new file mode 100644 index 0000000..0368b34 --- /dev/null +++ b/store.rb @@ -0,0 +1,14 @@ +require_relative './music/music_album' +require_relative './music/genre' +require_relative './app' +require 'json' + +module Storage + def save_music_albums; end + + def load_music_albums; end + + def save_genres; end + + def load_genres; end +end From f32e5155041b31c15e11f51697052f8947ce4917 Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Wed, 31 May 2023 08:34:04 -0700 Subject: [PATCH 58/75] author and game tables --- Database/schema.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Database/schema.sql b/Database/schema.sql index 25ba846..46fe34c 100644 --- a/Database/schema.sql +++ b/Database/schema.sql @@ -21,3 +21,18 @@ CREATE TABLE book ( genre TEXT ); +-- create game table +CREATE TABLE game ( + id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + published_date DATE, + multiplayer BOOLEAN NOT NULL DEFAULT FALSE, + last_played_at DATE, + author_id int REFERENCES author(id), +); + +-- create author table +CREATE TABLE author ( + id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + first_name VARCHAR(100) NOT NULL, + last_name VARCHAR(100) NOT NULL, +); \ No newline at end of file From 50c514fc95d7745bfa3e127d21ba193c73316f5d Mon Sep 17 00:00:00 2001 From: brhanuhailu Date: Thu, 1 Jun 2023 04:12:55 -0700 Subject: [PATCH 59/75] join everyone one file togther --- app.rb | 10 +-- handler.rb | 1 + main.rb | 190 +++++++++++++++++++-------------------- src/music/music_album.rb | 4 +- store.rb | 4 +- store/authors.json | 5 ++ store/books.json | 24 +++++ store/games.json | 7 ++ store/genres.json | 14 ++- store/labels.json | 10 +++ store/music_albums.json | 17 ++-- 11 files changed, 162 insertions(+), 124 deletions(-) diff --git a/app.rb b/app.rb index 5830b79..c27f2c3 100644 --- a/app.rb +++ b/app.rb @@ -6,8 +6,8 @@ require_relative 'author' require 'json' require 'date' -require_relative './src/genre' -require_relative './src/music_album' +require_relative './src/music/genre' +require_relative './src/music/music_album' require_relative './handler' class App < Handler @@ -98,7 +98,7 @@ def list_authors puts 'List of Authors:' puts '=============================================:' puts 'ID - First Name - Last Name' - authors.each do |author| + @authors.each do |author| puts "#{author['id']} - #{author['first_name']} - #{author['last_name']}" end puts '=============================================:' @@ -119,8 +119,8 @@ def create_games puts 'Enter last name' last_name = gets.chomp author = create_author(first_name, last_name) - authors << author - @store.save_data(authors, './store/authors.json') + @authors << author + @store.save_data(@authors, './store/authors.json') game = create_game_object(game_name, last_played_at, publish_date, multiplayer) @games << game @store.save_data(@games, './store/games.json') diff --git a/handler.rb b/handler.rb index 7431e50..5c0151d 100644 --- a/handler.rb +++ b/handler.rb @@ -1,4 +1,5 @@ require_relative './store' +require_relative 'storage' class Handler include JsonStorage diff --git a/main.rb b/main.rb index 754d6da..a6f2d22 100644 --- a/main.rb +++ b/main.rb @@ -1,95 +1,95 @@ -require_relative 'app' - -class MainMenu - attr_reader :app - - def initialize(app) - @app = app - end - - def user_options(choice) - menu_options = { - 1 => method(:list_books), - 2 => method(:list_music), - 3 => method(:list_games), - 4 => method(:list_genres), - 5 => method(:list_labels), - 6 => method(:list_authors), - 7 => method(:create_book), - 8 => method(:create_music), - 9 => method(:create_games), - 0 => method(:exit_app) - } - if menu_options.key?(choice) - menu_options[choice].call(app) - else - puts 'Invalid option, please try again!' - end - end - - def display - puts 'Welcome to your library' - puts 'Please choose an option' - puts '1. List all books' - puts '2. List all music albums' - puts '3. List all games' - puts '4. List all genres' - puts '5. List all labels' - puts '6. List all authors' - puts '7. Create a book' - puts '8. Create a music album' - puts '9. Create a game' - puts '0. Exit' - end - - def list_books(app) - app.list_books - end - - def list_music(app) - app.list_music - end - - def list_games(app) - app.list_games - end - - def list_genres(app) - app.list_genres - end - - def list_labels(app) - app.list_labels - end - - def list_authors(app) - app.list_authors - end - - def create_book(app) - app.create_book - end - - def create_music(app) - app.create_music - end - - def create_games(app) - app.create_games - end - - def exit_app(app) - app.exit_app - end -end - -def main - app = App.new - main_menu = MainMenu.new(app) - loop do - main_menu.display - choice = gets.chomp.to_i - main_menu.user_options(choice) - end -end -main +require_relative 'app' + +class MainMenu + attr_reader :app + + def initialize(app) + @app = app + end + + def user_options(choice) + menu_options = { + 1 => method(:list_books), + 2 => method(:list_music), + 3 => method(:list_games), + 4 => method(:list_genres), + 5 => method(:list_labels), + 6 => method(:list_authors), + 7 => method(:create_book), + 8 => method(:create_music), + 9 => method(:create_games), + 0 => method(:exit_app) + } + if menu_options.key?(choice) + menu_options[choice].call(app) + else + puts 'Invalid option, please try again!' + end + end + + def display + puts 'Welcome to your library' + puts 'Please choose an option' + puts '1. List all books' + puts '2. List all music albums' + puts '3. List all games' + puts '4. List all genres' + puts '5. List all labels' + puts '6. List all authors' + puts '7. Create a book' + puts '8. Create a music album' + puts '9. Create a game' + puts '0. Exit' + end + + def list_books(app) + app.list_books + end + + def list_music(app) + app.albums + end + + def list_games(app) + app.list_games + end + + def list_genres(app) + app.genres + end + + def list_labels(app) + app.list_labels + end + + def list_authors(app) + app.list_authors + end + + def create_book(app) + app.create_book + end + + def create_music(app) + app.add_music_album + end + + def create_games(app) + app.create_games + end + + def exit_app(app) + app.exit_app + end +end + +def main + app = App.new + main_menu = MainMenu.new(app) + loop do + main_menu.display + choice = gets.chomp.to_i + main_menu.user_options(choice) + end +end +main diff --git a/src/music/music_album.rb b/src/music/music_album.rb index 889c1a0..109cf54 100644 --- a/src/music/music_album.rb +++ b/src/music/music_album.rb @@ -12,13 +12,13 @@ # All data should be preserved by saving collections in .json files. # Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: # music_albums table (add all properties and associations from the parent Item class as table columns) -require_relative '../item' +require_relative '../../item' class MusicAlbum < Item attr_accessor :name, :publish_date, :on_spotify def initialize(name, publish_date, on_spotify) @id = Random.rand(1..1000) - super(publish_date, archived) + super(nil, nil, publish_date, archived) @name = name @on_spotify = on_spotify end diff --git a/store.rb b/store.rb index 0368b34..27bf353 100644 --- a/store.rb +++ b/store.rb @@ -1,5 +1,5 @@ -require_relative './music/music_album' -require_relative './music/genre' +require_relative './src/music/music_album' +require_relative './src/music/genre' require_relative './app' require 'json' diff --git a/store/authors.json b/store/authors.json index 84913c2..577eee9 100644 --- a/store/authors.json +++ b/store/authors.json @@ -23,5 +23,10 @@ "id": 868, "first_name": "kebede", "last_name": "melaku" + }, + { + "id": 393, + "first_name": "baedd", + "last_name": "dagdg" } ] \ No newline at end of file diff --git a/store/books.json b/store/books.json index 74b0a2c..9640fb1 100644 --- a/store/books.json +++ b/store/books.json @@ -82,5 +82,29 @@ "title": "iction", "color": "red" } + }, + { + "id": 82, + "author": "yodi", + "published_date": "2023-2-1", + "publisher": "puplisher", + "cover_state": "good", + "label": { + "id": 569, + "title": "title", + "color": "color" + } + }, + { + "id": 901, + "author": "dfsdf", + "published_date": "2023-2-2", + "publisher": "ghgh", + "cover_state": "goood", + "label": { + "id": 323, + "title": "trer", + "color": "fgfdg" + } } ] \ No newline at end of file diff --git a/store/games.json b/store/games.json index d72c13c..748a9dc 100644 --- a/store/games.json +++ b/store/games.json @@ -33,5 +33,12 @@ "last_played_at": "2023-02-05", "publish_date": "2022-04-01", "multiplayer": true + }, + { + "id": 222, + "game_name": "Gametwo", + "last_played_at": "2023-02-01", + "publish_date": "2023-02-03", + "multiplayer": true } ] \ No newline at end of file diff --git a/store/genres.json b/store/genres.json index 2a4237f..94b4e3d 100644 --- a/store/genres.json +++ b/store/genres.json @@ -1,10 +1,6 @@ [ - { - "genre_id" : 77, - "genre_name" : "yyyy" - }, - { - "genre_id" : 570, - "genre_name" : "tttt" - } - ] \ No newline at end of file + { + "genre_id" : 577, + "genre_name" : "gesd" + } +] \ No newline at end of file diff --git a/store/labels.json b/store/labels.json index a29fdf6..c220bec 100644 --- a/store/labels.json +++ b/store/labels.json @@ -33,5 +33,15 @@ "id": 214, "title": "iction", "color": "red" + }, + { + "id": 569, + "title": "title", + "color": "color" + }, + { + "id": 323, + "title": "trer", + "color": "fgfdg" } ] \ No newline at end of file diff --git a/store/music_albums.json b/store/music_albums.json index 2f611fb..a8d7d79 100644 --- a/store/music_albums.json +++ b/store/music_albums.json @@ -1,12 +1,7 @@ [ - { - "music_id" : 45, - "music_name" : "www", - "music_on_spotify" : true - }, - { - "music_id" : 53, - "music_name" : "8", - "music_on_spotify" : true - } - ] \ No newline at end of file + { + "music_id" : 455, + "music_name" : "aedgd", + "music_on_spotify" : true + } +] \ No newline at end of file From e7a9a2fe55bba02c69640c7459df91d463f939c0 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 15:49:54 +0300 Subject: [PATCH 60/75] Create tests for genre and music --- Gemfile | 1 + item.rb | 2 +- spec/genre_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ spec/music_album_spec.rb | 16 ++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 spec/genre_spec.rb create mode 100644 spec/music_album_spec.rb diff --git a/Gemfile b/Gemfile index b7683a4..bb11156 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ source 'https://rubygems.org' gem 'rubocop', '>= 1.0', '< 2.0' +gem 'rspec' \ No newline at end of file diff --git a/item.rb b/item.rb index 36031e0..23729d9 100644 --- a/item.rb +++ b/item.rb @@ -27,4 +27,4 @@ def label=(label) @label = label label.add_item(self) end -end +end \ No newline at end of file diff --git a/spec/genre_spec.rb b/spec/genre_spec.rb new file mode 100644 index 0000000..038b1b7 --- /dev/null +++ b/spec/genre_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' +require_relative '../src/music/genre' + +RSpec.describe Genre do + let(:name) { "Action" } + let(:id) { 42 } + let(:item) { double("Item") } + subject { Genre.new(name, id: id) } + + describe "#initialize" do + it "sets the name" do + expect(subject.name).to eq(name) + end + + it "sets the id" do + expect(subject.id).to eq(id) + end + + it "initializes an empty items array" do + expect(subject.items).to be_empty + end + end + + describe "#add_item" do + it "adds the item to the items array" do + subject.add_item(item) + expect(subject.items).to include(item) + end + + it "sets the genre on the item" do + expect(item).to receive(:genres=).with(subject) + subject.add_item(item) + end + end + end + \ No newline at end of file diff --git a/spec/music_album_spec.rb b/spec/music_album_spec.rb new file mode 100644 index 0000000..aadd811 --- /dev/null +++ b/spec/music_album_spec.rb @@ -0,0 +1,16 @@ +require_relative '../src/music/music_album' +require_relative '../item' +describe MusicAlbum do + context 'Given an instance of the music album class' do + before :each do + @music = MusicAlbum.new('Kaweesi', '2013-09-03', true) + end + + it 'creates an instance of the music album class' do + expect(@music).to be_instance_of MusicAlbum + end + it 'return true for the can be archived method' do + expect(@music.can_be_archived?).to be nil + end + end +end \ No newline at end of file From cdf207291b3a52780e4400c89eca4c2937c36f3d Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 15:57:29 +0300 Subject: [PATCH 61/75] fix linters --- Gemfile | 8 +++--- item.rb | 2 +- spec/genre_spec.rb | 57 ++++++++++++++++++++-------------------- spec/music_album_spec.rb | 2 +- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Gemfile b/Gemfile index bb11156..38159e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' - -gem 'rubocop', '>= 1.0', '< 2.0' -gem 'rspec' \ No newline at end of file +source 'https://rubygems.org' + +gem 'rspec'gem 'rubocop', '>= 1.0', '< 2.0' + diff --git a/item.rb b/item.rb index 23729d9..36031e0 100644 --- a/item.rb +++ b/item.rb @@ -27,4 +27,4 @@ def label=(label) @label = label label.add_item(self) end -end \ No newline at end of file +end diff --git a/spec/genre_spec.rb b/spec/genre_spec.rb index 038b1b7..ef9b9a2 100644 --- a/spec/genre_spec.rb +++ b/spec/genre_spec.rb @@ -2,35 +2,34 @@ require_relative '../src/music/genre' RSpec.describe Genre do - let(:name) { "Action" } - let(:id) { 42 } - let(:item) { double("Item") } - subject { Genre.new(name, id: id) } - - describe "#initialize" do - it "sets the name" do - expect(subject.name).to eq(name) - end - - it "sets the id" do - expect(subject.id).to eq(id) - end - - it "initializes an empty items array" do - expect(subject.items).to be_empty - end + let(:name) { 'Action' } + let(:id) { 42 } + let(:item) { double('Item') } + subject { Genre.new(name, id: id) } + + describe '#initialize' do + it 'sets the name' do + expect(subject.name).to eq(name) + end + + it 'sets the id' do + expect(subject.id).to eq(id) + end + + it 'initializes an empty items array' do + expect(subject.items).to be_empty end - - describe "#add_item" do - it "adds the item to the items array" do - subject.add_item(item) - expect(subject.items).to include(item) - end - - it "sets the genre on the item" do - expect(item).to receive(:genres=).with(subject) - subject.add_item(item) - end + end + + describe '#add_item' do + it 'adds the item to the items array' do + subject.add_item(item) + expect(subject.items).to include(item) + end + + it 'sets the genre on the item' do + expect(item).to receive(:genres=).with(subject) + subject.add_item(item) end end - \ No newline at end of file +end diff --git a/spec/music_album_spec.rb b/spec/music_album_spec.rb index aadd811..8ad1a89 100644 --- a/spec/music_album_spec.rb +++ b/spec/music_album_spec.rb @@ -13,4 +13,4 @@ expect(@music.can_be_archived?).to be nil end end -end \ No newline at end of file +end From 9f36b239c0ecfa1280809efc3295be4b6de502f5 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 16:05:01 +0300 Subject: [PATCH 62/75] fix bug --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 38159e9..448e2e4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' -gem 'rspec'gem 'rubocop', '>= 1.0', '< 2.0' +gem 'rubocop', '>= 1.0', '< 2.0' From c722997d6c54a890a217ec5eed947e7ebfb40be8 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 16:49:46 +0300 Subject: [PATCH 63/75] fix bugs --- .bundle/config | 2 ++ spec/genre_spec.rb | 35 +++++++++++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 .bundle/config diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 0000000..6d9698e --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_PATH: "ruby-capstone" diff --git a/spec/genre_spec.rb b/spec/genre_spec.rb index ef9b9a2..39a1497 100644 --- a/spec/genre_spec.rb +++ b/spec/genre_spec.rb @@ -1,35 +1,34 @@ -require 'spec_helper' -require_relative '../src/music/genre' +require 'rspec' +require 'json' -RSpec.describe Genre do - let(:name) { 'Action' } - let(:id) { 42 } +describe Genre do + let(:genre_name) { 'Comedy' } let(:item) { double('Item') } - subject { Genre.new(name, id: id) } + let(:genre) { Genre.new(genre_name) } describe '#initialize' do - it 'sets the name' do - expect(subject.name).to eq(name) + it 'should set the name' do + expect(genre.name).to eq(genre_name) end - it 'sets the id' do - expect(subject.id).to eq(id) + it 'should generate an id' do + expect(genre.id).to be_a(Integer) end - it 'initializes an empty items array' do - expect(subject.items).to be_empty + it 'should initialize an empty items collection' do + expect(genre.items).to be_empty end end describe '#add_item' do - it 'adds the item to the items array' do - subject.add_item(item) - expect(subject.items).to include(item) + it 'should add the item to the items collection' do + genre.add_item(item) + expect(genre.items).to include(item) end - it 'sets the genre on the item' do - expect(item).to receive(:genres=).with(subject) - subject.add_item(item) + it 'should set self as a property of the item object' do + expect(item).to receive(:genres=).with(genre) + genre.add_item(item) end end end From 0979c029058844dfab1212fdb1640d4e2714622f Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 17:20:11 +0300 Subject: [PATCH 64/75] fix tests --- spec/genre_spec.rb | 40 +++++++++++++++++++++------------------- spec/music_album_spec.rb | 4 ++-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/spec/genre_spec.rb b/spec/genre_spec.rb index 39a1497..b40d0cd 100644 --- a/spec/genre_spec.rb +++ b/spec/genre_spec.rb @@ -1,34 +1,36 @@ -require 'rspec' -require 'json' +require 'spec_helper' +require_relative '../src/music/genre' -describe Genre do - let(:genre_name) { 'Comedy' } - let(:item) { double('Item') } - let(:genre) { Genre.new(genre_name) } +RSpec.describe Genre do + let(:name) { 'Action' } + let(:id) { 42 } + item = Item.new('genre', 'name', 'published_date') + + subject { Genre.new(name, id: id) } describe '#initialize' do - it 'should set the name' do - expect(genre.name).to eq(genre_name) + it 'sets the name' do + expect(subject.name).to eq(name) end - it 'should generate an id' do - expect(genre.id).to be_a(Integer) + it 'sets the id' do + expect(subject.id).to eq(id) end - it 'should initialize an empty items collection' do - expect(genre.items).to be_empty + it 'initializes an empty items array' do + expect(subject.items).to be_empty end end describe '#add_item' do - it 'should add the item to the items collection' do - genre.add_item(item) - expect(genre.items).to include(item) + it 'adds the item to the items array' do + subject.add_item(item) + expect(subject.items).to include(item) end - it 'should set self as a property of the item object' do - expect(item).to receive(:genres=).with(genre) - genre.add_item(item) + it 'sets the genre on the item' do + expect(item).to receive(:genre=).with(subject) + subject.add_item(item) end end -end +end \ No newline at end of file diff --git a/spec/music_album_spec.rb b/spec/music_album_spec.rb index 8ad1a89..f87c9e9 100644 --- a/spec/music_album_spec.rb +++ b/spec/music_album_spec.rb @@ -10,7 +10,7 @@ expect(@music).to be_instance_of MusicAlbum end it 'return true for the can be archived method' do - expect(@music.can_be_archived?).to be nil + expect(@music.can_be_archived?).to be true end end -end +end \ No newline at end of file From 05f2e4dcc2e37ef2b4e2b34c4d35e9d1bf1509b2 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 17:26:49 +0300 Subject: [PATCH 65/75] fix linter errors --- Gemfile | 1 - spec/genre_spec.rb | 2 +- spec/music_album_spec.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 448e2e4..1a22d6d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ source 'https://rubygems.org' gem 'rubocop', '>= 1.0', '< 2.0' - diff --git a/spec/genre_spec.rb b/spec/genre_spec.rb index b40d0cd..a7c1d1e 100644 --- a/spec/genre_spec.rb +++ b/spec/genre_spec.rb @@ -33,4 +33,4 @@ subject.add_item(item) end end -end \ No newline at end of file +end diff --git a/spec/music_album_spec.rb b/spec/music_album_spec.rb index f87c9e9..047bfa0 100644 --- a/spec/music_album_spec.rb +++ b/spec/music_album_spec.rb @@ -13,4 +13,4 @@ expect(@music.can_be_archived?).to be true end end -end \ No newline at end of file +end From 933c09dfeaaec2873def44b51395679fb7e9f91b Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 20:27:57 +0300 Subject: [PATCH 66/75] fis tests --- spec/genre_spec.rb | 7 ------- spec/music_album_spec.rb | 1 - src/music/genre.rb | 2 ++ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/spec/genre_spec.rb b/spec/genre_spec.rb index a7c1d1e..d34b4b7 100644 --- a/spec/genre_spec.rb +++ b/spec/genre_spec.rb @@ -1,33 +1,26 @@ require 'spec_helper' require_relative '../src/music/genre' - RSpec.describe Genre do let(:name) { 'Action' } let(:id) { 42 } item = Item.new('genre', 'name', 'published_date') - subject { Genre.new(name, id: id) } - describe '#initialize' do it 'sets the name' do expect(subject.name).to eq(name) end - it 'sets the id' do expect(subject.id).to eq(id) end - it 'initializes an empty items array' do expect(subject.items).to be_empty end end - describe '#add_item' do it 'adds the item to the items array' do subject.add_item(item) expect(subject.items).to include(item) end - it 'sets the genre on the item' do expect(item).to receive(:genre=).with(subject) subject.add_item(item) diff --git a/spec/music_album_spec.rb b/spec/music_album_spec.rb index 047bfa0..243482d 100644 --- a/spec/music_album_spec.rb +++ b/spec/music_album_spec.rb @@ -5,7 +5,6 @@ before :each do @music = MusicAlbum.new('Kaweesi', '2013-09-03', true) end - it 'creates an instance of the music album class' do expect(@music).to be_instance_of MusicAlbum end diff --git a/src/music/genre.rb b/src/music/genre.rb index 742d8d7..a19c112 100644 --- a/src/music/genre.rb +++ b/src/music/genre.rb @@ -11,6 +11,8 @@ # All data should be preserved by saving collections in .json files. # Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: # genres table +# genre.rb + class Genre attr_reader :items, :name, :id From 4bc9d230f14d111c9f7f462d6fc28433acc04fe8 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 20:54:53 +0300 Subject: [PATCH 67/75] update tests --- src/music/genre.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/music/genre.rb b/src/music/genre.rb index a19c112..c42e8ac 100644 --- a/src/music/genre.rb +++ b/src/music/genre.rb @@ -24,6 +24,6 @@ def initialize(name, id: rand(1..1000)) def add_item(item) @items << item - item.genres = self + item.genre = self end end From 80525e9532eca5492bd262486e7186ab77dfb771 Mon Sep 17 00:00:00 2001 From: daniel matama Date: Thu, 1 Jun 2023 21:00:57 +0300 Subject: [PATCH 68/75] update schema file --- Database/schema.sql | 27 +++++++++++++++++++++++++++ src/music/schema_2.sql | 28 ---------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) delete mode 100644 src/music/schema_2.sql diff --git a/Database/schema.sql b/Database/schema.sql index 46fe34c..02ab4ac 100644 --- a/Database/schema.sql +++ b/Database/schema.sql @@ -35,4 +35,31 @@ CREATE TABLE author ( id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, first_name VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL, +); + +-- create genre table +CREATE TABLE Genre( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + name VARCHAR(60) NOT NULL +); + +-- create item table + +CREATE TABLE item( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + genre_id INT, + author_id INT, + label_id INT, + publish_date Date, + archived BOOLEAN, + FOREIGN KEY(genre_id) REFERENCES Genre(id) ON UPDATE CASCADE, + FOREIGN KEY(author_id) REFERENCES Author(id) ON UPDATE CASCADE, + FOREIGN KEY(label_id) REFERENCES Label(id) ON UPDATE CASCADE +); + +-- create music_album table +CREATE TABLE MusicAlbum( + id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + on_spotify BOOLEAN NOT NULL, + FOREIGN KEY(id) REFERENCES item(id) ON UPDATE CASCADE ); \ No newline at end of file diff --git a/src/music/schema_2.sql b/src/music/schema_2.sql deleted file mode 100644 index 86805c8..0000000 --- a/src/music/schema_2.sql +++ /dev/null @@ -1,28 +0,0 @@ --- create genre table -CREATE TABLE Genre( - id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name VARCHAR(60) NOT NULL -); - --- create item table - -CREATE TABLE item( - id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - genre_id INT, - author_id INT, - source_id INT, - label_id INT, - publish_date Date, - archived BOOLEAN, - FOREIGN KEY(genre_id) REFERENCES Genre(id) ON UPDATE CASCADE, - FOREIGN KEY(author_id) REFERENCES Author(id) ON UPDATE CASCADE, - FOREIGN KEY(source_id) REFERENCES Source(id) ON UPDATE CASCADE, - FOREIGN KEY(label_id) REFERENCES Label(id) ON UPDATE CASCADE -); - --- create music_album table -CREATE TABLE MusicAlbum( - id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - on_spotify BOOLEAN NOT NULL, - FOREIGN KEY(id) REFERENCES item(id) ON UPDATE CASCADE -); \ No newline at end of file From 733fe45a54bf5ca05cb0686b56ec40c06ff79281 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Thu, 1 Jun 2023 22:08:07 +0300 Subject: [PATCH 69/75] Finilized catalog of my things --- .rspec | 1 - Database/schema.sql | 5 +- README.md | 99 ++++++++++------------------------------ app.rb | 6 +-- src/music/genre.rb | 15 ------ src/music/music_album.rb | 14 ------ store/authors.json | 10 ++++ store/books.json | 12 +++++ store/games.json | 7 +++ store/genres.json | 8 +++- store/labels.json | 5 ++ store/music_albums.json | 9 +++- 12 files changed, 74 insertions(+), 117 deletions(-) delete mode 100644 .rspec diff --git a/.rspec b/.rspec deleted file mode 100644 index 82b8369..0000000 --- a/.rspec +++ /dev/null @@ -1 +0,0 @@ ---require spec_helper \ No newline at end of file diff --git a/Database/schema.sql b/Database/schema.sql index 02ab4ac..f949bde 100644 --- a/Database/schema.sql +++ b/Database/schema.sql @@ -12,13 +12,12 @@ CREATE TABLE label ( -- create book table CREATE TABLE book ( id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - author TEXT, + author_id INT REFERENCES author(id), published_date DATE, publisher TEXT, archived BOOLEAN NOT NULL DEFAULT FALSE, cover_state VARCHAR(5), - label_id int REFERENCES label(id), - genre TEXT + label_id INT REFERENCES label(id) ); -- create game table diff --git a/README.md b/README.md index f3f74ef..ecc3c62 100644 --- a/README.md +++ b/README.md @@ -61,20 +61,18 @@ ### Key Features -> Describe between 1-3 key features of the application. - -- **[Add Music optiion for end user]** -- **[Library Data Keeping]** -- **[Add game optiion for end users]** +- **[User Interface]** - **[Add Database to store the whole data]** +- **[preserve data in json format]**

(back to top)

- + + +## 🚀 Video Link -## 🚀 Live Demo +> - [Video Link]() -> Not applicable.

(back to top)

@@ -82,83 +80,56 @@ ## 💻 Getting Started -> Describe how a new developer could make use of your project. - To get a local copy up and running, follow these steps. ### Prerequisites In order to run this project you need: - ### Setup Clone this repository to your desired folder: - + ### Install Install this project with: - - ### Usage To run the project, execute the following command: - - - ### Run tests -To run tests, run the following command: - - +### Run unit tests +To run unit tests, run the following command: +```sh + Rspec +``` ### Deployment -You can deploy this project using: +Not applicable. -

(back to top)

@@ -166,8 +137,6 @@ Example: ## 👥 Authors -> Mention all of the collaborators of this project. - 👤 **Daniel Matama** - GitHub: [@Recillah-Khamala](https://github.com/danielmatama) @@ -192,11 +161,8 @@ Example: ## 🔭 Future Features -> Describe 1 - 3 features you will add to the project. - -- [ ] **[Add unit tests]** -- [ ] **[Create databases]** -- [ ] **[Create file for persist data]** +- [ ] **[Add more unit tests]** +- [ ] **[Create complete databases]**

(back to top)

@@ -214,9 +180,7 @@ Feel free to check the [issues page](https://github.com/brhanuhailu/ruby-capston ## ⭐️ Show your support -> Write a message to encourage readers to support your project - -If you like this project... +If you like this project give a ⭐️ and We are so excited to accept you feedback to improve our profession.

(back to top)

@@ -224,27 +188,10 @@ If you like this project... ## 🙏 Acknowledgments -> Give credit to everyone who inspired your codebase. - we would like to thank Microverse

(back to top)

- - -## ❓ FAQ (OPTIONAL) - -> Add at least 2 questions new developers would ask when they decide to use your project. - -- **[Question_1]** - - - [Answer_1] - -- **[Question_2]** - - - [Answer_2] - -

(back to top)

diff --git a/app.rb b/app.rb index c27f2c3..39b089d 100644 --- a/app.rb +++ b/app.rb @@ -4,19 +4,17 @@ require_relative 'game' require_relative './store/preserve_data' require_relative 'author' -require 'json' -require 'date' require_relative './src/music/genre' require_relative './src/music/music_album' require_relative './handler' +require 'json' +require 'date' class App < Handler def initialize super @genres = [] @music_albums = [] - - # @storage = Storage.new(self) @store = PreserveData.new @books = File.empty?('./store/books.json') ? [] : @store.load_data('./store/books.json') @labels = File.empty?('./store/labels.json') ? [] : @store.load_data('./store/labels.json') diff --git a/src/music/genre.rb b/src/music/genre.rb index c42e8ac..56899a7 100644 --- a/src/music/genre.rb +++ b/src/music/genre.rb @@ -1,18 +1,3 @@ -# Create Genre class with an association to the Item class (in a separate .rb file). -# All Genre class properties visible in the diagram should be defined and set up in the constructor method. -# Implement methods: -# add_item method in the Genre class -# should take an instance of the Item class as an input -# should add the input item to the collection of items -# should add self as a property of the item object (by using the correct setter from the item object) -# Add unit tests for all implemented methods. -# The following options should be available: -# List all genres (e.g 'Comedy', 'Thriller') -# All data should be preserved by saving collections in .json files. -# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: -# genres table -# genre.rb - class Genre attr_reader :items, :name, :id diff --git a/src/music/music_album.rb b/src/music/music_album.rb index 109cf54..a93ae7b 100644 --- a/src/music/music_album.rb +++ b/src/music/music_album.rb @@ -1,17 +1,3 @@ -# Create MusicAlbum class in a separate .rb file. -# All MusicAlbum class properties visible in the diagram should be defined and set up in the constructor method. -# Implement methods: -# can_be_archived?() in the MusicAlbum class -# should override the method from the parent class -# should return true if parent's method returns true AND if on_spotify equals true -# otherwise, it should return false -# Add unit tests for all implemented methods. -# The following options should be available: -# List all music albums -# Add a music album -# All data should be preserved by saving collections in .json files. -# Create a schema.sql file with tables that will be analogical to the structure of the classes that you created: -# music_albums table (add all properties and associations from the parent Item class as table columns) require_relative '../../item' class MusicAlbum < Item attr_accessor :name, :publish_date, :on_spotify diff --git a/store/authors.json b/store/authors.json index 577eee9..a137120 100644 --- a/store/authors.json +++ b/store/authors.json @@ -28,5 +28,15 @@ "id": 393, "first_name": "baedd", "last_name": "dagdg" + }, + { + "id": 113, + "first_name": "mario", + "last_name": "littel" + }, + { + "id": 548, + "first_name": "yodit", + "last_name": "abebe" } ] \ No newline at end of file diff --git a/store/books.json b/store/books.json index 9640fb1..fae7efa 100644 --- a/store/books.json +++ b/store/books.json @@ -106,5 +106,17 @@ "title": "trer", "color": "fgfdg" } + }, + { + "id": 767, + "author": "a", + "published_date": "2012", + "publisher": "pub", + "cover_state": "bad", + "label": { + "id": 544, + "title": "science", + "color": "red" + } } ] \ No newline at end of file diff --git a/store/games.json b/store/games.json index 748a9dc..8ab9352 100644 --- a/store/games.json +++ b/store/games.json @@ -40,5 +40,12 @@ "last_played_at": "2023-02-01", "publish_date": "2023-02-03", "multiplayer": true + }, + { + "id": 229, + "game_name": "mario", + "last_played_at": "2023-09-01", + "publish_date": "1990-04-03", + "multiplayer": true } ] \ No newline at end of file diff --git a/store/genres.json b/store/genres.json index 94b4e3d..5591b3d 100644 --- a/store/genres.json +++ b/store/genres.json @@ -1,6 +1,10 @@ [ { - "genre_id" : 577, - "genre_name" : "gesd" + "genre_id" : 517, + "genre_name" : "genre" + }, + { + "genre_id" : 553, + "genre_name" : "genre" } ] \ No newline at end of file diff --git a/store/labels.json b/store/labels.json index c220bec..8dbdf12 100644 --- a/store/labels.json +++ b/store/labels.json @@ -43,5 +43,10 @@ "id": 323, "title": "trer", "color": "fgfdg" + }, + { + "id": 544, + "title": "science", + "color": "red" } ] \ No newline at end of file diff --git a/store/music_albums.json b/store/music_albums.json index a8d7d79..e2058c3 100644 --- a/store/music_albums.json +++ b/store/music_albums.json @@ -1,7 +1,12 @@ [ { - "music_id" : 455, - "music_name" : "aedgd", + "music_id" : 500, + "music_name" : "album", + "music_on_spotify" : true + }, + { + "music_id" : 888, + "music_name" : "mm", "music_on_spotify" : true } ] \ No newline at end of file From b2d00f38bc3aca0eb934d8bc0fd9cf8c72e6b200 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Fri, 2 Jun 2023 09:34:52 +0300 Subject: [PATCH 70/75] Import spec_helper.rb to author_spec.rb --- spec/author_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/author_spec.rb b/spec/author_spec.rb index 2522f53..7eac509 100644 --- a/spec/author_spec.rb +++ b/spec/author_spec.rb @@ -1,3 +1,4 @@ +require_relative './spec_helper' RSpec.describe Author do describe '#add_author' do let(:author) { Author.new('John', 'Doe') } From eb223d92329acdd1f77fa0e8aa473b5fa3c15c74 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Fri, 2 Jun 2023 11:36:01 +0300 Subject: [PATCH 71/75] Add video link to readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ecc3c62..dcf2361 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ ## 🚀 Video Link -> - [Video Link]() +> - [Video Link](https://drive.google.com/file/d/1jBsHmWNemll98kqnGH5JWwbRKP6Eb4G9/view?usp=sharing)

(back to top)

From 14e206c7a6d5fe8e47ddffb5894d2c0d5ab379bc Mon Sep 17 00:00:00 2001 From: yodit93 Date: Fri, 2 Jun 2023 16:33:16 +0300 Subject: [PATCH 72/75] Update readme file --- README.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/README.md b/README.md index dcf2361..bf04f7d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,3 @@ - - - -
- logo -
- -

Catalogue_Of_My_Things

- -
- # 📗 Table of Contents From c1c506063143e808fde0152355038b03f8303402 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Fri, 2 Jun 2023 16:33:52 +0300 Subject: [PATCH 73/75] Add unit tests for item class methods --- spec/item_spec.rb | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 spec/item_spec.rb diff --git a/spec/item_spec.rb b/spec/item_spec.rb new file mode 100644 index 0000000..9a8780d --- /dev/null +++ b/spec/item_spec.rb @@ -0,0 +1,70 @@ +require_relative './spec_helper' +describe Book do + before(:all) do + @label = Label.new('Fiction', 'blue') + @item = Item.new('genre', 'author', '2020-01-01', nil) + end + + describe '#initialize' do + it 'creates a new item instance' do + expect(@item).to be_an_instance_of Item + end + + it 'the genre of the item should be "genre"' do + expect(@item.genre).to eq('genre') + end + + it 'the author of the item should be "author"' do + expect(@item.author).to eq('author') + end + + it 'the publication date of the book should be "2010-01-01"' do + expect(@item.published_date).to eq('2020-01-01') + end + + it 'the label of the book should be a Label instance' do + expect(@item.label).to be nil + end + end + + describe '#can_be_archived?' do + it 'should return false for less than 10 years' do + expect(@item.can_be_archived?).to eq(false) + end + + it 'should return true for more than 10 years' do + @item.published_date = '2010-01-01' + expect(@item.can_be_archived?).to eq(true) + end + end + + describe '#move_to_archive' do + it 'should return true if can_be_archived? is true' do + @item.published_date = '2010-01-01' + expect(@item.move_to_archive).to eq(true) + end + end + + describe '#label=' do + it 'should add the item to the label' do + @item.label = @label + expect(@label.items).to include(@item) + end + end + + describe '#author=' do + it 'should add the item to the author' do + author = Author.new('John', 'Doe') + @item.author = author + expect(author.items).to include(@item) + end + end + + describe '#genre=' do + it 'should add the item to the genre' do + genre = Genre.new('Fiction') + @item.genre = genre + expect(genre.items).to include(@item) + end + end +end From 71dadbb04fcd2a59ccf0be51f9e458434cf8034b Mon Sep 17 00:00:00 2001 From: yodit93 Date: Fri, 2 Jun 2023 16:34:53 +0300 Subject: [PATCH 74/75] Add custom setters for author and genre classes in item --- item.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/item.rb b/item.rb index 36031e0..998ec96 100644 --- a/item.rb +++ b/item.rb @@ -1,9 +1,8 @@ require 'date' -require_relative 'label' class Item - attr_reader :id, :archived, :label - attr_accessor :genre, :author, :published_date + attr_reader :id, :label, :author, :genre + attr_accessor :published_date, :archived def initialize(genre, author, published_date, label = nil) @id = Random.rand(1..1000) @@ -25,6 +24,16 @@ def move_to_archive def label=(label) @label = label - label.add_item(self) + label.add_item(self) unless label.items.include?(self) + end + + def author=(author) + @author = author + author.add_author(self) unless author.items.include?(self) + end + + def genre=(genre) + @genre = genre + genre.add_item(self) unless genre.items.include?(self) end end From fdfcec1483720111fdaf566af2b8507b26b33dd5 Mon Sep 17 00:00:00 2001 From: yodit93 Date: Fri, 2 Jun 2023 16:35:43 +0300 Subject: [PATCH 75/75] Check rubocop --- spec/spec_helper.rb | 1 + store/authors.json | 5 +++++ store/books.json | 12 ++++++++++++ store/games.json | 7 +++++++ store/genres.json | 8 ++------ store/labels.json | 5 +++++ store/music_albums.json | 11 +---------- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a2d8063..4416388 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,3 +3,4 @@ require_relative '../game' require_relative '../author' require_relative '../item' +require_relative '../src/music/genre' diff --git a/store/authors.json b/store/authors.json index a137120..955d61d 100644 --- a/store/authors.json +++ b/store/authors.json @@ -38,5 +38,10 @@ "id": 548, "first_name": "yodit", "last_name": "abebe" + }, + { + "id": 753, + "first_name": "first", + "last_name": "last" } ] \ No newline at end of file diff --git a/store/books.json b/store/books.json index fae7efa..cd225c4 100644 --- a/store/books.json +++ b/store/books.json @@ -118,5 +118,17 @@ "title": "science", "color": "red" } + }, + { + "id": 418, + "author": "e", + "published_date": "56", + "publisher": "p", + "cover_state": "bad", + "label": { + "id": 462, + "title": "la", + "color": "c" + } } ] \ No newline at end of file diff --git a/store/games.json b/store/games.json index 8ab9352..37d357e 100644 --- a/store/games.json +++ b/store/games.json @@ -47,5 +47,12 @@ "last_played_at": "2023-09-01", "publish_date": "1990-04-03", "multiplayer": true + }, + { + "id": 826, + "game_name": "game", + "last_played_at": "2010-02-01", + "publish_date": "1998-02-01", + "multiplayer": true } ] \ No newline at end of file diff --git a/store/genres.json b/store/genres.json index 5591b3d..2e76b1b 100644 --- a/store/genres.json +++ b/store/genres.json @@ -1,10 +1,6 @@ [ { - "genre_id" : 517, - "genre_name" : "genre" - }, - { - "genre_id" : 553, - "genre_name" : "genre" + "genre_id" : 422, + "genre_name" : "g" } ] \ No newline at end of file diff --git a/store/labels.json b/store/labels.json index 8dbdf12..9617913 100644 --- a/store/labels.json +++ b/store/labels.json @@ -48,5 +48,10 @@ "id": 544, "title": "science", "color": "red" + }, + { + "id": 462, + "title": "la", + "color": "c" } ] \ No newline at end of file diff --git a/store/music_albums.json b/store/music_albums.json index e2058c3..c44dc44 100644 --- a/store/music_albums.json +++ b/store/music_albums.json @@ -1,12 +1,3 @@ [ - { - "music_id" : 500, - "music_name" : "album", - "music_on_spotify" : true - }, - { - "music_id" : 888, - "music_name" : "mm", - "music_on_spotify" : true - } + ] \ No newline at end of file