Class: BlueCrossPets::Cat

Inherits:
Pet
  • Object
show all
Defined in:
lib/blue_cross_pets/cat.rb

Constant Summary collapse

@@cats =
[]

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) ⇒ Cat

Returns a new instance of Cat.



7
8
9
10
11
12
13
# File 'lib/blue_cross_pets/cat.rb', line 7

def initialize(pet_hash)
  pet_hash.each do |attribute, value|
    self.send("#{attribute}=".to_sym, value)
  end

  @@cats << self
end

Class Method Details

.allObject



15
16
17
# File 'lib/blue_cross_pets/cat.rb', line 15

def self.all
  @@cats
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/cat.rb', line 37

def self.get_more_info(input)

  index = input.to_i - 1
  cat = all[index]

  if !cat.reference
    attribute_hash = BlueCrossPets::Scraper.scrape_profile(cat.profile_url)
    cat.add_attributes(attribute_hash)
  elsif cat.reference
  end

  puts "----------------------------- All about #{cat.name} -----------------------------".blue
  puts "Age: ".light_white + "#{cat.age}"
  puts "Gender: ".light_white + "#{cat.gender}"
  puts "Availability: ".light_white + "#{cat.availability}"
  puts "Breed & colour: ".light_white + "#{cat.breed_and_colour}"

  if cat.can_live_with
    puts "Can live with: ".light_white + "#{cat.can_live_with}"
  end

  puts "Bio: ".light_white + "#{cat.bio}"
  puts "Animal reference number: ".light_white + "#{cat.reference}"
  puts "Visit my page: ".light_white + "#{cat.profile_url}"
end

.list_allObject



19
20
21
22
23
# File 'lib/blue_cross_pets/cat.rb', line 19

def self.list_all
  self.all.each_with_index do |cat, index|
    puts "#{index + 1}. ".blue + "#{cat.name} - #{cat.breed} - #{cat.gender} - #{cat.age} - #{cat.availability}"
  end
end

.scrape_catsObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/blue_cross_pets/cat.rb', line 25

def self.scrape_cats

  if all.length == 0
    cat_array = BlueCrossPets::Scraper.scrape_index("https://www.bluecross.org.uk/rehome/cat")
    create_from_index(cat_array)
    list_all
  elsif all.length > 0
    list_all
  end

end