Class: PetFinder::Pet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atts = {}) ⇒ Pet

Returns a new instance of Pet.



6
7
8
9
10
# File 'lib/pet_finder/pet.rb', line 6

def initialize(atts={})
  atts.each do |key, value|
    self.send("#{key}=", value) if respond_to?(key)
  end
end

Instance Attribute Details

#ageObject

Returns the value of attribute age.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def age
  @age
end

#animalObject

Returns the value of attribute animal.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def animal
  @animal
end

#breedsObject

Returns the value of attribute breeds.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def breeds
  @breeds
end

#contactObject

Returns the value of attribute contact.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def contact
  @contact
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def id
  @id
end

#lastUpdateObject

Returns the value of attribute lastUpdate.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def lastUpdate
  @lastUpdate
end

#mediaObject

Returns the value of attribute media.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def media
  @media
end

#mixObject

Returns the value of attribute mix.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def mix
  @mix
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def name
  @name
end

#sexObject

Returns the value of attribute sex.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def sex
  @sex
end

#shelterIdObject

Returns the value of attribute shelterId.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def shelterId
  @shelterId
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def size
  @size
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/pet_finder/pet.rb', line 4

def status
  @status
end

Instance Method Details

#get_photosObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pet_finder/pet.rb', line 12

def get_photos
  my_photos = {}
  photos = media['photos']['photo']
  all_photos = []
  0..5.times do |x|
    all_photos << photos.select do |p|
      p_id = p.match(/([1-5])-\w+\.jpg$/)[1]
      p_id == x.to_s
    end
  end
  all_photos.each_with_index do |photo_array, idx|
    res_hash = {
      '500x500' => nil,
      'max50_height' => nil,
      '300x250' => nil,
      'max60_wide' => nil,
      'max95_wide' => nil
    }
    photo_array.each do |photo_url|
      res_hash['500x500'] = photo_url if photo_url.match(/x\.jpg$/)
      res_hash['max50_height'] = photo_url if photo_url.match(/t\.jpg$/)
      res_hash['300x250'] = photo_url if photo_url.match(/pn\.jpg$/)
      res_hash['max60_wide'] = photo_url if photo_url.match(/pnt\.jpg$/)
      res_hash['max95_wide'] = photo_url if photo_url.match(/fpm\.jpg$/)
    end
    my_photos["photo_#{idx.to_s}"] = res_hash unless res_hash.values.compact.empty?
  end
  my_photos      
end