Class: AnimalFactory

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(species, object) ⇒ AnimalFactory

Returns a new instance of AnimalFactory.



3
4
5
6
7
8
9
10
11
12
# File 'lib/animalfactory.rb', line 3

def initialize(species, object)
  if species == "Small"
    @species = "small-furry"
  else
    @species = species.downcase
  end
  @animal_object = object

  scrape_and_create_animals
end

Class Method Details

.add_attributes_to_animals(number, animal_object) ⇒ Object



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

def self.add_attributes_to_animals(number, animal_object)
  pet = animal_object.all[number]
  attributes = Scraper.scrape_pet_profile(pet.url)
  pet.add_attributes(attributes)
end

Instance Method Details

#scrape_and_create_animalsObject

Scrapes page ending with /@species and creates new objects based on the previously defined species object



14
15
16
17
# File 'lib/animalfactory.rb', line 14

def scrape_and_create_animals # Scrapes page ending with /@species and creates new objects based on the previously defined species object
  hash_of_pets = Scraper.scrape_adoptable_pets(@species)
  @animal_object.create_new(hash_of_pets)
end