Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions LoRyder1/controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative 'view'
require_relative 'model'

class GameController
include GameView

def run!
animalsZoo = Zoo.new

Print::run_spinner
Print::title_screen

loop do
Print::menagerie
case Print::get_user_input
when "A"
Print::print_zoo(animalsZoo.animals)
when "B"
animalsZoo.add_animal(Print::serialize_animal)
when "C"
animalsZoo.export_animal(Print::deleted_id.to_i)
when "D"
puts "Thanks for visiting the Zoo"
exit
else
Print::error_message
end
end
end
end

GameController.new.run!
47 changes: 47 additions & 0 deletions LoRyder1/model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'faker'

class Animal
attr_reader :id, :name, :description, :weight, :dangerous

def initialize args
@id = args[:id]
@name = args[:name]
@description = args[:description]
@weight = args[:weight]
@dangerous = nil
end
end

class Zoo
attr_reader :animals

def initialize
@primary_id = 0
@animals = []
import_animals
end

def add_animal(input)
@animals << Animal.new(input.merge(get_id))
end

def sell_animal(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think this method is used. its also a dup.

@animals.delete_if { |n| n.id == id}
end

def export_animal(id)
@animals.delete_if { |n| n.id == id }
end

def import_animals
add_animal(name: "Zebra", description: "part of the horse family with distinctive black and white stripes", weight: 700)
add_animal(name: "Elephant", description: "large mammals, herbivores, and gray", weight: 15000)
add_animal(name: "Lion", description: "big cat, male has mane, carnivore", weight: 440)
end

private

def get_id
{id: @primary_id +=1}
end
end
77 changes: 77 additions & 0 deletions LoRyder1/view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module GameView

module Print
class << self
def run_spinner
print "Loading (please wait) "
3.times { print "."; sleep 1; }
print "\n"
end

def error_message
puts "That key will not work. Have another go!"
end

def title_screen
title = <<-EOT

=============================
You Bought A Zoo
=============================


EOT
puts title
end

def menagerie
menagerie = <<-EOS

=== Welcome=====

- (A) View your animals
- (B) Add a animal
- (C) Export a animal
- (D) Quit program

========
EOS

puts menagerie
end

def print_zoo(animals)
animals.each do |animal|
puts "#{animal.id} || #{animal.name} - #{animal.description} - #{animal.weight}lbs"
end
end

def serialize_animal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{}.tap do |obj|
["\nEnter the animal name:", "\nEnter the description:", "\nEnter the weight:"].each do |t|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 't' here? avoid single character vars if you can.

# puts obj.inspect
if obj.empty?
obj[:name] = get_user_input(t)
elsif obj.count == 1
obj[:description] = get_user_input(t)
else
obj[:weight] = get_user_input(t)
end
end
end

end

def deleted_id
the_id = "\nEnter the id of the animal you want to sell"
get_user_input(the_id)
end

def get_user_input(question=nil)
puts question if question
print "> "
gets.chomp
end
end
end
end