Class: PetsSeekingPeople::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pets_seeking_people/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pet_inputObject

Returns the value of attribute pet_input.



3
4
5
# File 'lib/pets_seeking_people/cli.rb', line 3

def pet_input
  @pet_input
end

#zip_inputObject

Returns the value of attribute zip_input.



3
4
5
# File 'lib/pets_seeking_people/cli.rb', line 3

def zip_input
  @zip_input
end

Instance Method Details

#add_info_about_pet(list_pet) ⇒ Object



54
55
56
57
58
59
# File 'lib/pets_seeking_people/cli.rb', line 54

def add_info_about_pet(list_pet)
	  if !list_pet.info 
			info = PetsSeekingPeople::Scraper.scrape_animal_page(list_pet.animal_url)
			list_pet.add_animal_attributes(info)
		end
end

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pets_seeking_people/cli.rb', line 5

def call
 	puts "Welcome to pets seeking people!"
 	pet_type
 	zip
 	find_available_pets
    if PetsSeekingPeople::Pets.all == []
    	puts ""
		  puts "Sad day for you - there are no pets in your area up for adoption. You adopted them all!"
		  farewell
		else
			list_pets
			menu
			farewell
		end
end

#farewellObject



113
114
115
116
117
118
# File 'lib/pets_seeking_people/cli.rb', line 113

def farewell
	puts ""
	puts "Thanks for considering giving a lovely pet a home! Visit again soon."
	puts " ▼・ᴥ・▼ "
	puts ""
end

#find_available_petsObject



49
50
51
52
# File 'lib/pets_seeking_people/cli.rb', line 49

def find_available_pets
	animals_array = PetsSeekingPeople::Scraper.scrape_index_page(zip_input, pet_input)
	PetsSeekingPeople::Pets.create_from_collection(animals_array)
end

#list_details(list_pet) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pets_seeking_people/cli.rb', line 70

def list_details(list_pet)
	add_info_about_pet(list_pet)
	puts ""
	puts "-------------------  Here's info on #{list_pet.name}:  ---------------------"
	puts ""
	puts "Some deets you should know:"
	list_pet.info.each {|pet_fact| puts "#{pet_fact}"}
	puts ""
	puts "--------------------------------------------------------------------------"
	puts ""
	puts "If you want to adopt #{list_pet.name}, contact:"
	list_pet.adoption_contact.each {|contact| puts "#{contact}"}
	puts ""
	puts "--------------------------------------------------------------------------"
	puts ""
	puts "For more details on #{list_pet.name}, go to: #{list_pet.adoption_website}"
end

#list_petsObject



61
62
63
64
65
66
67
68
# File 'lib/pets_seeking_people/cli.rb', line 61

def list_pets
		puts ""
 	  puts "---------- These pets are available for adoption in your area: ----------"
 	  puts ""
 	  PetsSeekingPeople::Pets.all.each.with_index(1) do |pet, i|
 		  puts "#{i}. #{pet.name} - #{pet.breed} - #{pet.age} - #{pet.gender}"
	end
end


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/pets_seeking_people/cli.rb', line 88

def menu
	input = nil
	if input == "exit"
		farewell
	else 
		while input != 'exit'
		puts ""
		puts "---------------------------------- Menu ----------------------------------"
		puts "Enter the number of the pet you'd like more info."
		puts "Or type 'list' to see the list of available pets again."
		puts "Or type 'exit' to exit."
		puts "--------------------------------------------------------------------------"
		puts ""
		input = gets.strip.downcase

			if input.to_i > 0 && input.to_i <= PetsSeekingPeople::Pets.all.size
				list_pet = PetsSeekingPeople::Pets.find(input)
				list_details(list_pet)
			elsif input == "list"
				list_pets
			end
		end
	end
end

#pet_typeObject



21
22
23
24
25
26
27
28
29
# File 'lib/pets_seeking_people/cli.rb', line 21

def pet_type
	puts "If you're looking for a dog, type 'dog'. If you're looking for a cat, type 'cat'."
   @pet_input = gets.strip.downcase
    if !valid_pet_input?(pet_input)
    	puts ""
    	puts "While that's a lovely animal (or a typo), it's not an option."
  		self.pet_type
  	end
end

#valid_pet_input?(pet_input) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pets_seeking_people/cli.rb', line 41

def valid_pet_input?(pet_input)
	pet_input == "cat" || pet_input == "dog"
end

#valid_zip_code?(zip_input) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/pets_seeking_people/cli.rb', line 45

def valid_zip_code?(zip_input)
   /\A\d+\z/.match(zip_input) && zip_input.size == 5
end

#zipObject



31
32
33
34
35
36
37
38
39
# File 'lib/pets_seeking_people/cli.rb', line 31

def zip
	puts "What is your zip code?"
	@zip_input = gets.strip
	  if !valid_zip_code?(zip_input)
	  	puts ""
	  	puts "Oops, not a valid zip!"
	    self.zip
	  end
end