Class: BlueCrossPets::Dog
- Inherits:
-
Pet
- Object
- Pet
- BlueCrossPets::Dog
show all
- Defined in:
- lib/blue_cross_pets/dog.rb
Constant Summary
collapse
- @@dogs =
[]
Instance Attribute Summary
Attributes inherited from Pet
#age, #availability, #bio, #breed, #breed_and_colour, #can_live_with, #gender, #name, #profile_url, #reference
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Pet
#add_attributes, create_from_index
Constructor Details
#initialize(pet_hash) ⇒ Dog
Returns a new instance of Dog.
7
8
9
10
11
12
13
|
# File 'lib/blue_cross_pets/dog.rb', line 7
def initialize(pet_hash)
pet_hash.each do |attribute, value|
self.send("#{attribute}=".to_sym, value)
end
@@dogs << self
end
|
Class Method Details
.all ⇒ Object
15
16
17
|
# File 'lib/blue_cross_pets/dog.rb', line 15
def self.all
@@dogs
end
|
.get_more_info(input) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/blue_cross_pets/dog.rb', line 37
def self.get_more_info(input)
index = input.to_i - 1
dog = all[index]
if !dog.reference
attribute_hash = BlueCrossPets::Scraper.scrape_profile(dog.profile_url)
dog.add_attributes(attribute_hash)
elsif dog.reference
end
puts "----------------------------- All about #{dog.name} -----------------------------".blue
puts "Age: ".light_white + "#{dog.age}"
puts "Gender: ".light_white + "#{dog.gender}"
puts "Availability: ".light_white + "#{dog.availability}"
puts "Breed & colour: ".light_white + "#{dog.breed_and_colour}"
if dog.can_live_with
puts "Can live with: ".light_white + "#{dog.can_live_with}"
end
puts "Bio: ".light_white + "#{dog.bio}"
puts "Animal reference number: ".light_white + "#{dog.reference}"
puts "Visit my page: ".light_white + "#{dog.profile_url}"
end
|
.list_all ⇒ Object
19
20
21
22
23
|
# File 'lib/blue_cross_pets/dog.rb', line 19
def self.list_all
self.all.each_with_index do |dog, index|
puts "#{index + 1}. ".blue + "#{dog.name} - #{dog.breed} - #{dog.gender} - #{dog.age} - #{dog.availability}"
end
end
|
.scrape_dogs ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/blue_cross_pets/dog.rb', line 25
def self.scrape_dogs
if all.length == 0
dog_array = BlueCrossPets::Scraper.scrape_index("https://www.bluecross.org.uk/rehome/dog")
create_from_index(dog_array)
list_all
elsif all.length > 0
list_all
end
end
|