Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finished lab #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
14 changes: 12 additions & 2 deletions animal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ class Animal
# Example:
# Animal.new('Timmy', 4, 'male', 'toad')
def initialize(name, age, gender, species)

@name = name
@age = age
@gender = gender
@species = species
@toys = []
end

# When we display the animal using puts or print, the
# to_s method is called to pretty print an Animal
def to_s

return "#{@name} is a #{@age} year old #{@gender} #{@species} that loves #{@toys.join(", ")}"
end
end
# describe ".to_s" do
# it "prints the Animal object's attributes in a sentence" do
# expect(@animal.to_s).to match("Tiny is a 3 year old male cat that loves mice, string")
# end

#puts Animal.new("Tiny", 3, "male", "cat")
26 changes: 26 additions & 0 deletions client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

class Client

attr_accessor :name, :number_of_children, :age, :gender, :pets

def initialize(name, age, gender, number_of_children)
@name = name
@age = age
@gender = gender
@number_of_children = number_of_children
@pets = {}
end

def to_s
return "#{@name} is a #{@age} year old #{@gender} with #{@number_of_children} kids and #{pets.length} pets"
# expect(@client.to_s).to eql("Beth is a 30 year old female with 3 kids and 0 pets")

Choose a reason for hiding this comment

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

Glad you're (commenting and) adding tests throughout your project. It really helps guide the code.

end

def display_pets

Choose a reason for hiding this comment

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

Be careful with indentation! Come see me if you want some assistance on this.

pets_name = []
@pets.each do |k, v| pets_name.push(v.to_s)
end
return pets_name.join("\n")
end

end
10 changes: 5 additions & 5 deletions data.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# require the local files where the classes are defined
require_relative 'shelter'
require_relative 'person'
require_relative 'client'
require_relative 'animal'

# Instantiate a Shelter
$shelter = Shelter.new('HappiTails', '10 east 21st Street')

# Instantiate clients. Insert them into the shelter's clients hash
$shelter.clients['Bob'] = Person.new('Bob', 22, 'male', 0)
$shelter.clients['Sue'] = Person.new('Sue', 31, 'female', 2)
$shelter.clients['Jil'] = Person.new('Jil', 46, 'female', 1)
$shelter.clients['Sam'] = Person.new('Sam', 87, 'male', 3)
$shelter.clients['Bob'] = Client.new('Bob', 22, 'male', 0)
$shelter.clients['Sue'] = Client.new('Sue', 31, 'female', 2)
$shelter.clients['Jil'] = Client.new('Jil', 46, 'female', 1)
$shelter.clients['Sam'] = Client.new('Sam', 87, 'male', 3)

# Instantiate animals. Insert them into the shelter's animals hash
$shelter.animals['Spot'] = Animal.new('Spot', 3, 'male', 'Dog')
Expand Down
81 changes: 75 additions & 6 deletions main.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,79 @@
require 'pry'
require 'rainbow'
# require 'rainbow'
require_relative 'data'
require_relative 'animal'
require_relative 'client'
require_relative 'shelter'

Choose a reason for hiding this comment

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

The require relatives for "animal", "client", and "shelter" are not needed because these files are required in data.rb, and will be imported with line 3 in this file.


response = #set this equal to something
while response != 'Q'
##Fill in code here
puts "Welcome to the HappiTails Rescue Shelter!"

puts "Please pick an option: \n
(A) Display Animals \n
(B) Display Clients \n
(C) Create Animals \n
(D) Create Clients \n
(E) Adopt an animal \n
(F) Return an animal \n
(Q) Quit"
response = gets.chomp.upcase

Choose a reason for hiding this comment

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

Good way to catch and equalize responses from the user.


while response != "Q"
case response
when "A"
$shelter.display_animals
when "B"
$shelter.display_clients
when "C"
puts "Enter Name"
name = gets.chomp.capitalize.to_s
puts "Enter age"
age = gets.chomp.to_i
puts "Enter gender"
gender = gets.chomp.to_s
puts "Enter species"
species = gets.chomp.to_s
new_animal = Animal.new(name, age, gender,species)
$shelter.animals[name] = new_animal
when "D"
puts "Enter your name"
name = gets.chomp.to_s
puts "Enter your age"
age = gets.chomp.to_i
puts "Enter your gender"
gender = gets.chomp.to_s
puts "How many children do you have"
children = gets.chomp.to_i
new_client = Client.new(name, age, gender, children)
$shelter.clients[name] = new_client
when "E"
puts "What is your name?"
client_name = gets.chomp.capitalize.to_s
puts "Which animal do you want to adopt?"
animal_name = gets.chomp.capitalize.to_s
$shelter.animals.delete(animal_name)

Choose a reason for hiding this comment

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

Hmm, the adoption part seems incomplete and that was one of the most challenging parts of the lab. Can you tell what your logic behind it was? Try attempting it again, if you have time.

when "F"
#puts "NO RETURNS. ALL ADOPTIONS ARE FINAL."

Choose a reason for hiding this comment

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

Ha!

puts "Which animal do you want to return?"
animal_name = gets.chomp.capitalize.to_s
# new_animal = Animal.new(name)
$shelter.animals[name] = animal_name
when "Q"
end
puts "Please pick an option: \n
(A) Display Animals \n
(B) Display Clients \n
(C) Create Animals \n
(D) Create Clients \n
(E) Adopt an animal \n
(F) Return an animal \n
(Q) Quit"
response = gets.chomp.upcase
end


# response = #set this equal to something
# while response != 'Q'
# ##Fill in code here

response = #set this equal to something
end
# response = #set this equal to something
# end
35 changes: 35 additions & 0 deletions shelter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Shelter

attr_accessor :name, :address, :animals, :clients

def initialize(name, address)
@name = name
@address = address
@animals = {}
@clients = {}
end

def to_s
return "#{@name} shelter at #{@address} has #{@animals.count} animals and #{@clients.count} people"
end

def display_clients
$shelter.clients.each {|k, v| puts (v.to_s) + "\n"}
#return "#{@name} is a #{@age} year old #{@gender} 3 kids and 0 pets"
#return "Beth is a 30 year old female with 3 kids and 0 pets"
# client_arr = []
# @clients.each do |k,v|
# client_arr.push(v.to_s)
# end
# client_arr.join("\n")
end

def display_animals
$shelter.animals.each {|k,v| puts (v.to_s) + "\n"}

Choose a reason for hiding this comment

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

Try to use other variable names besides "k" and "v", like "animal" or "name" (or whatever the key and value actually describes). This helps with code readability and reminds of what key and value actually are.

# animals_arr = []
# @animals.each do |k, v|
# animals_arr.push(v.to_s)
# end
# animals_arr.join("\n")
end
end
4 changes: 2 additions & 2 deletions spec/shelter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

describe ".display_clients" do
it "prints the Shelter object's Clients" do
client = Person.new("Beth", 30, "female", 3)
@shelter.clients[client.name.to_sym] = client
client = Client.new("Beth", 30, "female", 3)
@shelter.clients[client.name] = client
expect(@shelter.display_clients).to match("Beth is a 30 year old female with 3 kids and 0 pets")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# For our specs to run, we need to require the Ruby classes we’re testing
require_relative '../animal'
require_relative '../shelter'
require_relative '../person'
require_relative '../client'

# Configure RSpec
RSpec.configure do |config|
Expand Down