-
Notifications
You must be signed in to change notification settings - Fork 29
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
HappiTails! #17
base: master
Are you sure you want to change the base?
HappiTails! #17
Changes from all commits
85d626b
9c813b8
19b8c76
8cdb119
f87b0c9
8bf11d6
5c4641d
ad8a575
a2d800f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
# Define Animal as a class | ||
class Animal | ||
|
||
# Set up accessors and mutators for the attributes of an Animal | ||
# attr_accessor sets up both for you | ||
attr_accessor :name, :age, :gender, :species, :toys | ||
|
||
# Used when creating a new 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 | ||
|
||
"#{@name} is a #{@age} year old #{@gender} #{@species} that loves #{@toys.join(", ")}" | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Client | ||
attr_accessor :name, :num_children, :age, :pets, :age, :gender | ||
|
||
def initialize(name, age, gender, num_children) | ||
@name = name | ||
@age = age | ||
@gender = gender | ||
@num_children = num_children | ||
@pets = {} | ||
end | ||
|
||
|
||
def to_s | ||
"#{@name} is a #{@age} year old #{@gender} with #{@num_children} kids and #{@pets.length} pets" | ||
end | ||
|
||
def display_pets | ||
pets = "" | ||
@pets.each do |k, v| | ||
pets += (v.to_s + "\n") | ||
end | ||
return pets.chomp() | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"result": { | ||
"covered_percent": 100.0 | ||
"covered_percent": 97.4 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,159 @@ | ||
{ | ||
"RSpec": { | ||
"coverage": { | ||
"/Users/jacquelineherrlin/GeneralAssembly/WDI_2014/animal_shelter/starter_code/animal.rb": [ | ||
"/Users/joshuapearson/GA/projects/happitails/HappiTailsMiniProject/animal.rb": [ | ||
1, | ||
null, | ||
1, | ||
1, | ||
4, | ||
4, | ||
4, | ||
4, | ||
4, | ||
null, | ||
null, | ||
1, | ||
3, | ||
null, | ||
null, | ||
null | ||
], | ||
"/Users/joshuapearson/GA/projects/happitails/HappiTailsMiniProject/shelter.rb": [ | ||
1, | ||
null, | ||
1, | ||
null, | ||
1, | ||
5, | ||
5, | ||
5, | ||
5, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
1, | ||
null, | ||
1, | ||
null, | ||
0, | ||
null, | ||
null, | ||
0, | ||
null, | ||
null, | ||
null, | ||
null | ||
], | ||
"/Users/joshuapearson/GA/projects/happitails/HappiTailsMiniProject/client.rb": [ | ||
1, | ||
1, | ||
null, | ||
1, | ||
4, | ||
4, | ||
4, | ||
4, | ||
4, | ||
null, | ||
null, | ||
null, | ||
1, | ||
2, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
2, | ||
null, | ||
1, | ||
null, | ||
null, | ||
null | ||
], | ||
"/Users/jacquelineherrlin/GeneralAssembly/WDI_2014/animal_shelter/starter_code/shelter.rb": [ | ||
|
||
"/Users/joshuapearson/GA/projects/happitails/HappiTailsMiniProject/spec/client_spec.rb": [ | ||
1, | ||
null, | ||
1, | ||
null, | ||
1, | ||
3, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
1, | ||
1, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
null | ||
], | ||
"/Users/jacquelineherrlin/GeneralAssembly/WDI_2014/animal_shelter/starter_code/person.rb": [ | ||
|
||
"/Users/joshuapearson/GA/projects/happitails/HappiTailsMiniProject/spec/shelter_spec.rb": [ | ||
1, | ||
null, | ||
1, | ||
null, | ||
1, | ||
5, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
1, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
null, | ||
null, | ||
null | ||
] | ||
}, | ||
"timestamp": 1397016177 | ||
"timestamp": 1397233320 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
# 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.client['Bob'] = Client.new('Bob', 22, 'male', 0) | ||
$shelter.client['Sue'] = Client.new('Sue', 31, 'female', 2) | ||
$shelter.client['Jil'] = Client.new('Jil', 46, 'female', 1) | ||
$shelter.client['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') | ||
$shelter.animals['Spot'].toys << 'Bone' | ||
$shelter.animals['Lassy'] = Animal.new('Lassy', 2, 'female', 'Dog') | ||
$shelter.animals['Lassy'].toys << 'Frisbee' | ||
$shelter.animals['Molly'] = Animal.new('Molly', 5, 'female', 'Cat') | ||
$shelter.animals['Molly'].toys << 'Rope' | ||
$shelter.animals['Fido'] = Animal.new('Fido', 8, 'male', 'Dog') | ||
$shelter.animals['Fido'].toys << 'Chew Toy' | ||
$shelter.animals['Sport'] = Animal.new('Sport', 1, 'male', 'Dog') | ||
$shelter.animals['Sport'].toys << 'Treats' | ||
$shelter.animal['Spot'] = Animal.new('Spot', 3, 'male', 'Dog') | ||
$shelter.animal['Spot'].toys << 'Bone' | ||
$shelter.animal['Lassy'] = Animal.new('Lassy', 2, 'female', 'Dog') | ||
$shelter.animal['Lassy'].toys << 'Frisbee' | ||
$shelter.animal['Molly'] = Animal.new('Molly', 5, 'female', 'Cat') | ||
$shelter.animal['Molly'].toys << 'Rope' | ||
$shelter.animal['Fido'] = Animal.new('Fido', 8, 'male', 'Dog') | ||
$shelter.animal['Fido'].toys << 'Chew Toy' | ||
$shelter.animal['Sport'] = Animal.new('Sport', 1, 'male', 'Dog') | ||
$shelter.animal['Sport'].toys << 'Treats' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,92 @@ | ||
require 'pry' | ||
require 'rainbow' | ||
# require 'rainbow' | ||
require_relative 'data' | ||
require_relative 'functions' | ||
require_relative 'animal' | ||
require_relative 'client' | ||
require_relative 'shelter' | ||
|
||
response = #set this equal to something | ||
while response != 'Q' | ||
##Fill in code here | ||
|
||
response = #set this equal to something | ||
menu = <<PARAGRAPH | ||
\nWELCOME TO THE HAPPITAILS SHELTER APP!\n\n | ||
What would you like to do:\n\n | ||
Enter '1' to display all animals.\n | ||
Enter '2' to display all clients.\n | ||
Enter '3' to add a new animal to the shelter.\n | ||
Enter '4' to add a new client to the shelter.\n | ||
Enter '5' to adopt an animal.\n | ||
Enter '6' to return an animal to the shelter.\n | ||
Enter 'Q' to quit. | ||
PARAGRAPH | ||
print menu | ||
|
||
response = gets.chomp.upcase | ||
|
||
while response != "Q" | ||
|
||
case response | ||
when "1" | ||
puts "Here are the animals currently at the shelter:\n\n" | ||
puts $shelter.display_animals | ||
puts | ||
puts | ||
puts $shelter.to_s | ||
when "2" | ||
puts "Here are our current clients:\n\n" | ||
puts $shelter.display_clients | ||
puts | ||
puts | ||
puts $shelter.to_s | ||
when "3" | ||
puts "Please enter the name of the animal you would like to add to the shelter." | ||
animal_name = gets.chomp.capitalize | ||
puts "Please enter the age of the animal you are adding to the shelter." | ||
animal_age = gets.chomp.to_i | ||
puts "Please enter the gender of the animal." | ||
animal_gender = gets.chomp.downcase | ||
puts "Please enter the species of the animal." | ||
animal_species = gets.chomp.capitalize | ||
new_animal = Animal.new(animal_name, animal_age, animal_gender, animal_species) | ||
puts "Does this animal love any toys? If so enter the name of the toy below." | ||
new_animal.toys << gets.chomp | ||
puts "Thank you. The animal has now been added to the shelter database.\n\n" | ||
$shelter.animal[animal_name] = new_animal | ||
new_animal.to_s | ||
puts $shelter.display_animals | ||
when "4" | ||
puts "Please enter the first name of the new client you would like to add." | ||
client_name = gets.chomp.capitalize | ||
puts "Please enter the age of the client." | ||
client_age = gets.chomp.to_i | ||
puts "Please enter the gender of the client ('male' or 'female')" | ||
client_gender = gets.chomp.downcase | ||
puts "Please enter the number of childeren of the new client." | ||
client_num_children = gets.chomp.to_i | ||
new_client = Client.new(client_name, client_age, client_gender, client_num_children) | ||
puts "Thank you. Your new client has been added to the database.\n\n" | ||
$shelter.client[client_name] = new_client | ||
new_client.to_s | ||
puts $shelter.display_clients | ||
when "5" | ||
puts "Good news! A pet is being adopted.\n" | ||
puts "Please enter the name of the client who is adopting an animal." | ||
client_name = gets.chomp.capitalize | ||
puts "Please enter the name of the pet that is being adopted." | ||
pet_name = gets.chomp.capitalize | ||
puts "Thank you, #{client_name} is now the proud owner of #{pet_name}." | ||
$shelter.adopt(client_name, pet_name) | ||
puts $shelter.to_s | ||
when "6" | ||
puts "We're sorry that an animal is being returned.\n" | ||
puts "Please enter the animal being returned." | ||
pet_name = gets.chomp.capitalize | ||
puts "Please enter the name of the client who is returning the animal." | ||
client_name = gets.chomp.capitalize | ||
puts "Thank you, #{pet_name} has now been put back into the shelter database." | ||
$shelter.return(client_name, pet_name) | ||
when "Q" | ||
puts "Thank you for using the Happitails app." | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One additional comment. All the code within each of your "when" blocks of the case statement could be taken out and put into a method. That way the case statement would be made up of a bunch of method calls. It makes the code neater. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for all the feedback! It's greatly appreciated. From: Spencer Eldred [email protected] In main.rb:
|
||
|
||
print menu | ||
response = gets.chomp.upcase | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your use of the block quote to create a menu. Then you simply type print menu to display. You could have created a method that prints it for you, but this does the job nicely. It is much better than doing a puts for every line in the menu!