diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 14b18f92..3621b2a6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,37 +1,37 @@ -# Contributing to Learn.co Curriculum +Contributor Code of Conduct -We're really excited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible. +Our Pledge -## Raising an Issue to Encourage a Contribution +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. -If you notice a problem with the curriculum that you believe needs improvement -but you're unable to make the change yourself, you should raise a Github issue -containing a clear description of the problem. Include relevant snippets of -the content and/or screenshots if applicable. Curriculum owners regularly review -issue lists and your issue will be prioritized and addressed as appropriate. +Our Standards -## Submitting a Pull Request to Suggest an Improvement +Examples of behavior that contributes to creating a positive environment include: +Using welcoming and inclusive language +Being respectful of differing viewpoints and experiences +Gracefully accepting constructive criticism +Focusing on what is best for the community +Showing empathy towards other community members +Examples of unacceptable behavior by participants include: +The use of sexualized language or imagery and unwelcome sexual attention or advances +Trolling, insulting/derogatory comments, and personal or political attacks -If you see an opportunity for improvement and can make the change yourself go -ahead and use a typical git workflow to make it happen: +Public or private harassment -* Fork this curriculum repository -* Make the change on your fork, with descriptive commits in the standard format -* Open a Pull Request against this repo +Publishing others’ private information, such as a physical or electronic address, without explicit permission +Other conduct which could reasonably be considered inappropriate in a professional setting -A curriculum owner will review your change and approve or comment on it in due -course. +Our Responsibilities -# Why Contribute? +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. -Curriculum on Learn is publicly and freely available under Learn's -[Educational Content License](https://learn.co/content-license). By -embracing an open-source contribution model, our goal is for the curriculum -on Learn to become, in time, the best educational content the world has -ever seen. +Scope -We need help from the community of Learners to maintain and improve the -educational content. Everything from fixing typos, to correcting -out-dated information, to improving exposition, to adding better examples, -to fixing tests—all contributions to making the curriculum more effective are -welcome. +This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with +regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership. \ No newline at end of file diff --git a/Gemfile b/Gemfile index c004f4ca..0932688c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,6 @@ gem "sinatra-activerecord" gem "sqlite3" gem "pry" gem "require_all" +gem "tty-prompt" +gem "colorize" +gem "tty-font" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 9589226d..213071b5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,56 +1,74 @@ GEM remote: https://rubygems.org/ specs: - activemodel (6.0.3.1) - activesupport (= 6.0.3.1) - activerecord (6.0.3.1) - activemodel (= 6.0.3.1) - activesupport (= 6.0.3.1) - activesupport (6.0.3.1) + activemodel (6.0.3.4) + activesupport (= 6.0.3.4) + activerecord (6.0.3.4) + activemodel (= 6.0.3.4) + activesupport (= 6.0.3.4) + activesupport (6.0.3.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.2, >= 2.2.2) - coderay (1.1.1) - concurrent-ruby (1.1.6) - i18n (1.8.2) + coderay (1.1.3) + colorize (0.8.1) + concurrent-ruby (1.1.7) + i18n (1.8.5) concurrent-ruby (~> 1.0) - method_source (0.8.2) - minitest (5.14.1) - mustermann (1.0.3) - pry (0.10.4) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) + method_source (1.0.0) + minitest (5.14.2) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + pastel (0.8.0) + tty-color (~> 0.5) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) rack (2.2.3) - rack-protection (2.0.7) + rack-protection (2.1.0) rack - require_all (1.3.3) - sinatra (2.0.7) + require_all (3.0.0) + ruby2_keywords (0.0.2) + sinatra (2.1.0) mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.7) + rack (~> 2.2) + rack-protection (= 2.1.0) tilt (~> 2.0) - sinatra-activerecord (2.0.12) - activerecord (>= 3.2) + sinatra-activerecord (2.0.21) + activerecord (>= 4.1) sinatra (>= 1.0) - slop (3.6.0) - sqlite3 (1.3.13) + sqlite3 (1.4.2) thread_safe (0.3.6) tilt (2.0.10) - tzinfo (1.2.7) + tty-color (0.6.0) + tty-cursor (0.7.1) + tty-font (0.5.0) + tty-prompt (0.22.0) + pastel (~> 0.8) + tty-reader (~> 0.8) + tty-reader (0.8.0) + tty-cursor (~> 0.7) + tty-screen (~> 0.8) + wisper (~> 2.0) + tty-screen (0.8.1) + tzinfo (1.2.8) thread_safe (~> 0.1) - zeitwerk (2.3.0) + wisper (2.0.1) + zeitwerk (2.4.1) PLATFORMS ruby DEPENDENCIES + colorize pry require_all sinatra-activerecord sqlite3 + tty-font + tty-prompt BUNDLED WITH - 1.14.6 + 2.1.4 diff --git a/LICENSE.md b/LICENSE.md index 6802f2b8..9db510f7 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,20 @@ -#Learn.co Educational Content License +MIT License -Copyright (c) 2015 Flatiron School, Inc +Copyright (c) [2020] [Ruby Tank] -The Flatiron School, Inc. owns this Educational Content. However, the Flatiron School supports the development and availability of educational materials in the public domain. Therefore, the Flatiron School grants Users of the Flatiron Educational Content set forth in this repository certain rights to reuse, build upon and share such Educational Content subject to the terms of the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). You must read carefully the terms and conditions contained in the Educational Content License as such terms govern access to and use of the Educational Content. +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. -Flatiron School is willing to allow you access to and use of the Educational Content only on the condition that you accept all of the terms and conditions contained in the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). By accessing and/or using the Educational Content, you are agreeing to all of the terms and conditions contained in the Educational Content License. If you do not agree to any or all of the terms of the Educational Content License, you are prohibited from accessing, reviewing or using in any way the Educational Content. +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. \ No newline at end of file diff --git a/README.md b/README.md index b75f6185..be7e0f64 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,35 @@ -# Module One Final Project Guidelines +Application Features: -Congratulations, you're at the end of module one! You've worked crazy hard to get here and have learned a ton. +- A user can create a new user profile +- A user can create a virtual fish tank with a name and a specified number of fish +- User can add and remove fish from each tank that was created +- User can add other existing users as owners to their tank allowing the user to update the tank +- User can view their exisiting tanks +- User can update their tank and the tanks to which they are added to as an owner +- User can delete their existing tanks -For your final project, we'll be building a Command Line database application. +Built With: +- Ruby +- SQLite3 as database for Active Record +- Gems Used: + tty-prompt, + tty-font, + colorize -## Project Requirements +Install Instructions: + - Run bundle install + - Run ruby bin/run.rb -### Option One - Data Analytics Project +Contributing: +Constributing.md -1. Access a Sqlite3 Database using ActiveRecord. -2. You should have at minimum three models including one join model. This means you must have a many-to-many relationship. -3. You should seed your database using data that you collect either from a CSV, a website by scraping, or an API. -4. Your models should have methods that answer interesting questions about the data. For example, if you've collected info about movie reviews, what is the most popular movie? What movie has the most reviews? -5. You should provide a CLI to display the return values of your interesting methods. -6. Use good OO design patterns. You should have separate classes for your models and CLI interface. +Authors: +- Dominik Szarkiel +- Bartosz Minczuk - **Resource:** [Easy Access APIs](https://github.com/learn-co-curriculum/easy-access-apis) +Supporting Authors: +- Derick Castillo -### Option Two - Command Line CRUD App +License: +License.md -1. Access a Sqlite3 Database using ActiveRecord. -2. You should have a minimum of three models. -3. You should build out a CLI to give your user full CRUD ability for at least one of your resources. For example, build out a command line To-Do list. A user should be able to create a new to-do, see all todos, update a todo item, and delete a todo. Todos can be grouped into categories, so that a to-do has many categories and categories have many to-dos. -4. Use good OO design patterns. You should have separate classes for your models and CLI interface. - -### Brainstorming and Proposing a Project Idea - -Projects need to be approved prior to launching into them, so take some time to brainstorm project options that will fulfill the requirements above. You must have a minimum of four [user stories](https://en.wikipedia.org/wiki/User_story) to help explain how a user will interact with your app. A user story should follow the general structure of `"As a , I want so that "`. For example, if we were creating an app to randomly choose nearby restaurants on Yelp, we might write: - -* As a user, I want to be able to enter my name to retrieve my records -* As a user, I want to enter a location and be given a random nearby restaurant suggestion -* As a user, I should be able to reject a suggestion and not see that restaurant suggestion again -* As a user, I want to be able to save to and retrieve a list of favorite restaurant suggestions - -## Instructions - -1. Fork and clone this repository. -2. Build your application. Make sure to commit early and commit often. Commit messages should be meaningful (clearly describe what you're doing in the commit) and accurate (there should be nothing in the commit that doesn't match the description in the commit message). Good rule of thumb is to commit every 3-7 mins of actual coding time. Most of your commits should have under 15 lines of code and a 2 line commit is perfectly acceptable. -3. Make sure to create a good README.md with a short description, install instructions, a contributor's guide and a link to the license for your code. -4. Make sure your project checks off each of the above requirements. -5. Prepare a video demo (narration helps!) describing how a user would interact with your working project. - * The video should: - - Have an overview of your project. (2 minutes max) -6. Prepare a presentation to follow your video. (3 minutes max) - * Your presentation should: - - Describe something you struggled to build, and show us how you ultimately implemented it in your code. - - Discuss 3 things you learned in the process of working on this project. - - Address what, if anything, you would change or add to what you have today. - - Present any code you would like to highlight. -7. *OPTIONAL, BUT RECOMMENDED*: Write a blog post about the project and process. - ---- -### Common Questions: -- How do I turn off my SQL logger? -```ruby -# in config/environment.rb add this line: -ActiveRecord::Base.logger = nil -``` diff --git a/bin/run.rb b/bin/run.rb index cf08c338..4bc8eb4f 100644 --- a/bin/run.rb +++ b/bin/run.rb @@ -1,5 +1,5 @@ require_relative '../config/environment' - - -puts "HELLO WORLD" +App.new.run +system "clear" +puts "Thank you for playing, see you next time!" diff --git a/config/environment.rb b/config/environment.rb index 4dbe13e5..3f965dfc 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -2,4 +2,5 @@ Bundler.require ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.db') +ActiveRecord::Base.logger = nil require_all 'lib' diff --git a/db/migrate/01_create_owners.rb b/db/migrate/01_create_owners.rb new file mode 100644 index 00000000..298e6a60 --- /dev/null +++ b/db/migrate/01_create_owners.rb @@ -0,0 +1,9 @@ +class CreateOwners < ActiveRecord::Migration[5.2] + + def change + create_table :owners do |t| + t.string :name + end + end + +end \ No newline at end of file diff --git a/db/migrate/02_create_tanks.rb b/db/migrate/02_create_tanks.rb new file mode 100644 index 00000000..b45d6bc2 --- /dev/null +++ b/db/migrate/02_create_tanks.rb @@ -0,0 +1,9 @@ +class CreateTanks < ActiveRecord::Migration[5.2] + + def change + create_table :tanks do |t| + t.string :name + t.integer :fish_limit + end + end +end \ No newline at end of file diff --git a/db/migrate/03_create_tank_owner_ids.rb b/db/migrate/03_create_tank_owner_ids.rb new file mode 100644 index 00000000..3019cc39 --- /dev/null +++ b/db/migrate/03_create_tank_owner_ids.rb @@ -0,0 +1,10 @@ +class CreateTankOwnerIds < ActiveRecord::Migration[5.2] + + def change + create_table :tank_owner_ids do |t| + t.integer :owner_id + t.integer :tank_id + end + end + +end \ No newline at end of file diff --git a/db/migrate/04_create_fish.rb b/db/migrate/04_create_fish.rb new file mode 100644 index 00000000..5439cb25 --- /dev/null +++ b/db/migrate/04_create_fish.rb @@ -0,0 +1,11 @@ +class CreateFish < ActiveRecord::Migration[5.2] + + def change + create_table :fish do |t| + t.string :name + t.string :color + t.integer :tank_id + end + end + +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..eaa6fd7e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,35 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 4) do + + create_table "fish", force: :cascade do |t| + t.string "name" + t.string "color" + t.integer "tank_id" + end + + create_table "owners", force: :cascade do |t| + t.string "name" + end + + create_table "tank_owner_ids", force: :cascade do |t| + t.integer "owner_id" + t.integer "tank_id" + end + + create_table "tanks", force: :cascade do |t| + t.string "name" + t.integer "fish_limit" + end + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 00000000..024cdd63 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,27 @@ +Owner.destroy_all +Tank.destroy_all +TankOwnerId.destroy_all +Fish.destroy_all + +bart = Owner.create(name: "bart") +dom = Owner.create(name: "dom") +max = Owner.create(name: "max") +derick = Owner.create(name: "derick") +bob = Owner.create(name: "bob") + +tank1 = Tank.create(name: "tank1", fish_limit: 5) +tank2 = Tank.create(name: "tank2", fish_limit: 5) +tank3 =Tank.create(name: "tank3", fish_limit: 5) +tank4 =Tank.create(name: "tank4", fish_limit: 5) + +tank_owner_id_1 = TankOwnerId.create(owner_id: bart.id, tank_id: tank1.id) +tank_owner_id_2 = TankOwnerId.create(owner_id: dom.id, tank_id: tank2.id) +tank_owner_id_3 = TankOwnerId.create(owner_id: max.id, tank_id: tank3.id) +tank_owner_id_4 = TankOwnerId.create(owner_id: derick.id, tank_id: tank4.id) +tank_owner_id_5 = TankOwnerId.create(owner_id: dom.id, tank_id: tank1.id) + +nemo = Fish.create(name: "nemo", color: "orange", tank_id: tank1.id) +dory = Fish.create(name: "dory", color: "blue", tank_id: tank2.id) +guppy = Fish.create(name: "guppy", color: "gold", tank_id: tank3.id) +sharky = Fish.create(name: "sharky", color: "blue", tank_id: tank4.id) + diff --git a/lib/Large_bubble_sound.mp3 b/lib/Large_bubble_sound.mp3 new file mode 100644 index 00000000..84d2bdcb Binary files /dev/null and b/lib/Large_bubble_sound.mp3 differ diff --git a/lib/app.rb b/lib/app.rb new file mode 100644 index 00000000..8c59fd7e --- /dev/null +++ b/lib/app.rb @@ -0,0 +1,423 @@ +class App + + attr_accessor :current_user + attr_reader :fish + + def run + bubble_sound + show_intro_fish_tank + sleep(3,) + setup_owner + main_menu + end + + def main_menu + system "clear" + display_main_menu_title + prompt = TTY::Prompt.new + my_selection = prompt.select("What would you like to do?") do |menu| + menu.choice "Create Tank" + menu.choice "Update Tank" + menu.choice "See your Tank" + menu.choice "Add additional owner to the Tank" + menu.choice "Delete Tank" + menu.choice "Exit" + end + + if my_selection == "Create Tank" + create_tank + elsif my_selection == "Update Tank" + update_tank + elsif my_selection == "See your Tank" + see_your_tank + elsif my_selection == "Add additional owner to the Tank" + add_owner_to_tank + elsif my_selection == "Delete Tank" + delete_tank + elsif my_selection == "Exit" + puts "Thank you for playing, see you next time!" + sleep(2,) + system "clear" + exit + end + end + + def get_user_input + gets.chomp + end + +###################################### OWNER LOGIN ########################################### + + def setup_owner + system "clear" + prompt = TTY::Prompt.new + user_input = prompt.select("What's your owner status?") do |menu| + menu.choice "New Owner" + menu.choice "Existing Owner" + end + if user_input == "New Owner" + create_new_owner + else + find_existing_owner + end + end + + def create_new_owner + puts "Please enter your name:" + owner_name = gets.chomp.downcase + if Owner.find_by(name: owner_name) + system "clear" + puts "Sorry, that name is already taken." + create_new_owner + else + @current_user = Owner.create(name: owner_name) + puts "New user created! Welcome, #{current_user.name.capitalize}!" + end + end + + def find_existing_owner + puts "Please enter your name:" + owner_name = gets.chomp.downcase + @current_user = Owner.find_by(name: owner_name) + if Owner.all.map { |user| user.name }.include?(owner_name) + system "clear" + puts "Welcome back, #{current_user.name.capitalize}!" + else + puts "Username not found" + find_existing_owner + end + end +###################################### OWNER LOGIN END ########################################## + + def create_tank + system "clear" + display_main_menu_title + puts "What would you like your tank to be named?" + tank_name = get_user_input + puts "How many fish would you like to keep? (Max = 10)" + tank_limit = get_user_input.to_i + if Tank.find_by(name: tank_name) + puts "Sorry, that tank name is already in use. Please choose a different name!" + sleep(2,) + system "clear" + create_tank + elsif tank_limit > 10 + puts "Sorry, the tank is not big enough for more than 10 fish!" + sleep(2,) + system "clear" + create_tank + else + new_tank = Tank.create(name: tank_name, fish_limit: tank_limit) + TankOwnerId.create(owner_id: current_user.id , tank_id: new_tank.id) + end + puts "Congratulations! Your new tank #{tank_name} has been created." + sleep(2,) + main_menu + end + + def update_tank + display_tank_update_selection + display_my_fish_tank + prompt = TTY::Prompt.new + my_selection = prompt.select("What would you like to do? Add or remove fish?") do |menu| + menu.choice "Add Fish" + menu.choice "Remove Fish" + menu.choice "Back - Main Menu" + end + + if my_selection == "Add Fish" + add_fish + elsif my_selection == "Remove Fish" + remove_fish + elsif my_selection == "Back - Main Menu" + main_menu + end + end + +##################### FISH ADD/REMOVE FEATURES ################################################ + + def tank_fish_count + my_tank = Tank.find_by(name: @my_selection) + my_tank.fish.count + end + + + def add_fish + + if tank_fish_count.to_i < 10 + puts "What would you like to name your fish?" + fish_name = get_user_input + prompt = TTY::Prompt.new + color_selection = prompt.select("What color is the fish?") do |menu| + menu.choice "Gold" + menu.choice "Orange" + menu.choice "Blue" + end + fish_color = color_selection + my_tank = Tank.find_by(name: @my_selection) + Fish.create(name: fish_name, color: fish_color, tank_id: my_tank.id) + system "clear" + display_my_fish_tank + water_splash + sleep(3,) + main_menu + else + puts "Sorry, the tank is full!" + sleep(2,) + main_menu + end + end + + def remove_fish + puts "What fish would you like to remove?" + prompt = TTY::Prompt.new + deleted_fish = prompt.select("Which fish would you like to remove?", (display_my_fish_names)) + + my_tank = Tank.find_by(name: @my_selection) + my_fish = my_tank.fish.find_by(name: deleted_fish) + + my_fish.destroy + system "clear" + flush_sound + puts "Your fish has been successfully removed :(" + sleep(4.4,) + + main_menu + end + +################################# END OF FISH ADD/REMOVE FEATURES ######################################## + + def see_your_tank + display_tank_view_selection + display_my_fish_tank + puts display_tank_owners + + prompt = TTY::Prompt.new + go_back = prompt.select("Select Main Menu to go back") do |menu| + menu.choice "Main Menu" + end + if go_back == "Main Menu" + main_menu + end + end + + def add_owner_to_tank + # DIPLAY ALL CURRENT OWNER TANKS + my_tanks = current_user.tanks.map do |tank| + tank.name + end + if my_tanks.count == 0 + puts "You have no tanks to add owners to, please go back and create a tank first!" + sleep(2,) + main_menu + else + prompt = TTY::Prompt.new + add_owner_to = prompt.select("Which tank would you like to add an owner to", (my_tanks)) + end + #SELECT TANK THAT WE WANT TO ADD OWNER TO + my_tank = Tank.find_by(name: add_owner_to) + #ASK WHAT OWNER TO ADD + puts "Please type the name of the owner you would like to add" + additonal_owner = get_user_input.downcase + #DOES THAT OWNER EXIST, IF YES THEN RUN METHOD IF NO = ELSE. + new_owner = Owner.find_by(name: additonal_owner) + if Owner.find_by(name: additonal_owner) && !TankOwnerId.find_by(owner_id: new_owner.id, tank_id: my_tank.id) + TankOwnerId.create(owner_id: new_owner.id , tank_id: my_tank.id) + puts "New owner, #{new_owner.name.capitalize} has been added to #{my_tank.name}" + sleep(2,) + main_menu + else + puts "Sorry that owner was not found or that relationship already exists. Please try again." + sleep(2,) + main_menu + end + end + + def delete_tank + prompt = TTY::Prompt.new + selected_tank = prompt.select("What is the name of the tank that you would like to delete?", (display_my_tanks)) + deleted_tank = Tank.find_by(name: selected_tank) + + deleted_tank.destroy + glass_sound + puts "Your tank has been deleted successfully." + sleep(2,) + main_menu + end + +###################################### DISPLAY SECTION ######################################### + + def display_tank_update_selection + current_user.reload + my_tanks = current_user.tanks.map do |tank| + tank.name + end + if my_tanks.count == 0 + puts "You have no tanks to update, please go back and create a tank first!" + sleep(2,) + main_menu + else + prompt = TTY::Prompt.new + @my_selection = prompt.select("Which tank would you like to update?", (my_tanks)) + end + end + + def display_tank_owners + my_tank = Tank.find_by(name: @my_selection) + tank_owners = my_tank.owners + tank_owners.collect do |owner| + owner.name.capitalize + end + end + + def display_my_fish_tank + my_tank = Tank.find_by(name: @my_selection) + if my_tank.fish.count == 0 + display_empty_tank + elsif my_tank.fish.count == 1 + display_tank_one + elsif my_tank.fish.count == 2 + display_tank_two + elsif my_tank.fish.count == 3 + display_tank_three + elsif my_tank.fish.count == 4 + display_tank_four + elsif my_tank.fish.count == 5 + display_tank_five + elsif my_tank.fish.count == 6 + display_tank_six + elsif my_tank.fish.count == 7 + display_tank_seven + elsif my_tank.fish.count == 8 + display_tank_eight + elsif my_tank.fish.count == 9 + display_tank_nine + elsif my_tank.fish.count == 10 + display_full_tank + end +end + + def display_my_fish_names + my_tank = Tank.find_by(name: @my_selection) + my_fish = my_tank.fish + my_fish.map do |fish| + fish.name + end + end + + def display_my_tanks + current_user.reload + my_tanks = current_user.tanks.map do |tank| + tank.name + end + end + + def display_tank_view_selection + current_user.reload + my_tanks = current_user.tanks.map do |tank| + tank.name + end + if my_tanks.count == 0 + puts "You have no tanks to view, please go back and create a tank first!" + sleep(2,) + main_menu + else + prompt = TTY::Prompt.new + @my_selection = prompt.select("Which tank would you like to view", (my_tanks)) + end + end + + def display_title_intro + font = TTY::Font.new("Doom") + pastel = Pastel.new + puts pastel.cyan(font.write("WELCOME TO RUBY TANK")) + end + + def display_main_menu_title + font = TTY::Font.new("Standard") + pastel = Pastel.new + puts pastel.cyan(font.write("RUBY TANK")) + end + + + ############################### DISPLAY SECTION END ######################################### + + ################################## SOUND EFFECTS ############################################ + + def bubble_sound + pid = fork{exec 'afplay', "lib/Large_bubble_sound.mp3"} + end + + def flush_sound + pid = fork{exec 'afplay', "lib/flush_sound.mp3"} + end + + def glass_sound + pid = fork{exec 'afplay', "lib/glass_sound.mp3"} + end + + def water_splash + pid = fork{exec 'afplay', "lib/water_splash.mp3"} + end + ############################### SOUND EFFECTS END ########################################## + + ################################# VISUAL IMAGES ############################################ + + def show_intro_fish_tank + display_title_intro + Visual.show_intro_fish_tank + end + + def display_empty_tank + Visual.display_empty_tank + end + + def display_full_tank + Visual.display_full_tank + end + + def display_tank_one + Visual.display_tank_one + end + + def display_tank_two + Visual.display_tank_two + end + + def display_tank_three + Visual.display_tank_three + end + + def display_tank_four + Visual.display_tank_four + end + + def display_tank_five + Visual.display_tank_five + end + + def display_tank_six + Visual.display_tank_six + end + + def display_tank_seven + Visual.display_tank_seven + end + + def display_tank_eight + Visual.display_tank_eight + end + + def display_tank_nine + Visual.display_tank_nine + end + +end + + + + + + + + diff --git a/lib/fish.rb b/lib/fish.rb new file mode 100644 index 00000000..70ec7aa6 --- /dev/null +++ b/lib/fish.rb @@ -0,0 +1,6 @@ +class Fish < ActiveRecord::Base + + belongs_to :tank + has_many :owners, through: :tank + +end \ No newline at end of file diff --git a/lib/flush_sound.mp3 b/lib/flush_sound.mp3 new file mode 100644 index 00000000..849a8c66 Binary files /dev/null and b/lib/flush_sound.mp3 differ diff --git a/lib/glass_sound.mp3 b/lib/glass_sound.mp3 new file mode 100644 index 00000000..9e96a317 Binary files /dev/null and b/lib/glass_sound.mp3 differ diff --git a/lib/owner.rb b/lib/owner.rb new file mode 100644 index 00000000..0537b790 --- /dev/null +++ b/lib/owner.rb @@ -0,0 +1,6 @@ +class Owner < ActiveRecord::Base + has_many :tank_owner_ids + has_many :tanks, through: :tank_owner_ids + + +end \ No newline at end of file diff --git a/lib/tank.rb b/lib/tank.rb new file mode 100644 index 00000000..b875f4f4 --- /dev/null +++ b/lib/tank.rb @@ -0,0 +1,8 @@ +class Tank < ActiveRecord::Base + +has_many :fish +has_many :tank_owner_ids +has_many :owners, through: :tank_owner_ids + + +end diff --git a/lib/tank_owner_id.rb b/lib/tank_owner_id.rb new file mode 100644 index 00000000..84f36882 --- /dev/null +++ b/lib/tank_owner_id.rb @@ -0,0 +1,6 @@ +class TankOwnerId < ActiveRecord::Base + + belongs_to :owner + belongs_to :tank + +end \ No newline at end of file diff --git a/lib/visual.rb b/lib/visual.rb new file mode 100644 index 00000000..00a8fbc8 --- /dev/null +++ b/lib/visual.rb @@ -0,0 +1,146 @@ +class Visual + + def self.show_intro_fish_tank + puts" ".blue + puts" ___ ___ ___ ___ (( ".blue + puts" |___|___|___|___| (()) ".blue + puts" |:_:_:_:_:_| ".blue + "><>".red + " )) ".blue + puts" |_:_,--.:_:| ".blue + "<><".red + " (/// ) ".blue + puts" |:_:|__|_:_| ".blue + "><>".red + " _ ) )) (( ".blue + puts" _ |_ _ :_:| _ _ _ (_) (((( /))` ".blue + puts" | |_| |_| | _| | |_| |_| | o )))) (( ( ".blue + puts" |_:_:_:_:/|_|_|_| :_:_:_:_/ . ".blue + "<><".red + " (( )))) ".blue + puts" |_,-._:_:_:_:_:_:_:_.-,_| o )) ((// ".blue + puts" |:|_|:_:_:,---,:_:_:|_|:| o ,-. )/ ".blue + puts" |_:_:_:_,' `,_:_:_:_| _ o ,;'))(( ".blue + puts" |:_:_:_/ _ | _ _:_:_:| (_O (( )) ".blue + puts"_____|_:_:_| (o)-(o) |_:_:_|--'`-. ,--. (((('/ ".blue + puts" ', ;|:_:_:| -( .-. )- |:_:_:| ', ; `--._|oo|,---.~ ``)) ".blue + puts". ` |_:_:_| (`-') |_:_:_|. ` . ` |()|.__( ) .,-----' `-((( ".blue + puts" ', ;|:_:_:| `-' |:_:_:| ', ; ', ; `--'| \ ', ; ', ; ',')).,-- ".blue + puts" . ` ` . ` . ` . ` . ` . ` . ` . . ` . ` . ` . ` . ` ".yellow + puts" ', ; ', ; ', ; ', ; ', ; ', ; ', ; ', ; ', ; ', ; ', ; ', ; ', ', ; ".yellow + end + + def self.display_empty_tank + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| |".blue + puts "| |".blue + puts "| _\\/_ |".blue + puts "| /o\\ |".blue + puts "| | |".blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_full_tank + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|" .blue + puts "| ><> <>< <>< |" .blue + puts "| ><> <>< |" .blue + puts "| ><> _\\/_ |".blue + puts "| <>< ><> /o\\ |".blue + puts "| <>< | <><|" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|" .yellow + puts "|_____________________________________________________|" .yellow + + end + + def self.display_tank_one + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| |".blue + puts "| |".blue + puts "| _\\/_ |".blue + puts "| ><> /o\\ |".blue + puts "| | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_two + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| |".blue + puts "| |".blue + puts "| ><> _\\/_ |".blue + puts "| /o\\ |".blue + puts "| <>< | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_three + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| |".blue + puts "| <>< |".blue + puts "| ><> _\\/_ |".blue + puts "| /o\\ |".blue + puts "| <>< | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_four + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| <>< <>< |".blue + puts "| |".blue + puts "| ><> _\\/_ |".blue + puts "| /o\\ |".blue + puts "| ><> | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_five + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| <>< <>< |".blue + puts "| ><> |".blue + puts "| ><> _\\/_ |".blue + puts "| /o\\ |".blue + puts "| ><> | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_six + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| <>< |".blue + puts "| ><> |".blue + puts "| ><> <>< _\\/_ |".blue + puts "| <>< /o\\ |".blue + puts "| ><> | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_seven + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| ><> <>< |".blue + puts "| <>< |".blue + puts "| <>< _\\/_ |".blue + puts "| ><> <>< /o\\ |".blue + puts "| ><> | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_eight + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| ><> <>< |".blue + puts "| ><> ><> |".blue + puts "| ><> _\\/_ |".blue + puts "| <>< ><> /o\\ |".blue + puts "| <>< | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end + + def self.display_tank_nine + puts "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|".blue + puts "| ><> <>< ><> |".blue + puts "| <>< |".blue + puts "| ><> _\\/_ |".blue + puts "| <>< <>< /o\\ |".blue + puts "| ><> <>< | |" .blue + puts "|,,,,......,,,,...,,..,.,..,,..,,..,,,,,,,..,.,.|..,.,|".yellow + puts "|_____________________________________________________|".yellow + end +end \ No newline at end of file diff --git a/lib/water_splash.mp3 b/lib/water_splash.mp3 new file mode 100644 index 00000000..1c09d7a8 Binary files /dev/null and b/lib/water_splash.mp3 differ