Class: AdoptAPet::Pet

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

Overview

Base class for Adopt-A-Pet Pet objects

Author:

  • Stephen Dolan

Defined Under Namespace

Classes: Photo, ResponseHelper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Pet

Create a single instance of a Pet

Parameters:

  • object (Hash)

    a JSON response object from the Adopt-A-Pet API

Author:

  • Stephen Dolan



86
87
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/adopt_a_pet/pet.rb', line 86

def initialize(object) # rubocop:disable all
  extract(object, %w[pet_id],          'id')
  extract(object, %w[pet_code],        'pet_code')
  extract(object, %w[age],             'age')
  extract(object, %w[sex],             'sex')
  extract(object, %w[size],            'size')
  extract(object, %w[species],         'species')
  extract(object, %w[act_quickly],     'act_quickly')
  extract(object, %w[color],           'color')
  extract(object, %w[special_needs],   'special_needs')
  extract(object, %w[purebred],        'purebred')
  extract(object, %w[description],     'description')
  extract(object, %w[good_with_dogs],  'good_with_dogs')
  extract(object, %w[declawed],        'declawed')
  extract(object, %w[spayed_neutered], 'spayed_neutered')
  extract(object, %w[housetrained],    'housetrained')
  extract(object, %w[shots_current],   'shots_current')
  extract(object, %w[good_with_kids],  'good_with_kids')
  extract(object, %w[primary_breed],   'primary_breed')
  extract(object, %w[secondary_breed], 'secondary_breed')
  extract(object, %w[addr_state_code], 'state_code')
  extract(object, %w[addr_city],       'city')
  extract(object, %w[name pet_name],   'name')
  extract(object, %w[details_url pet_details_url], 'details_url')
  self.photos = ResponseHelper.extract_photos(object)
end

Instance Attribute Details

#act_quicklyString

Returns a string denoting whether action is required quickly for adoption.

Returns:

  • (String)

    a string denoting whether action is required quickly for adoption



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#ageString

Returns a description of the age of the pet.

Returns:

  • (String)

    a description of the age of the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#cityString

Returns the city where the pet resides.

Returns:

  • (String)

    the city where the pet resides



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#colorString

Returns a description of the color of the pet.

Returns:

  • (String)

    a description of the color of the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#declawedString

Returns a string denoting whether or not the pet is declawed.

Returns:

  • (String)

    a string denoting whether or not the pet is declawed



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#descriptionString

Returns a description of the pet.

Returns:

  • (String)

    a description of the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#details_urlString

Returns a link to the details page for the pet on Adopt-A-Pet.

Returns:

  • (String)

    a link to the details page for the pet on Adopt-A-Pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#good_with_dogsString

Returns a string denoting whether or not the pet is good with dogs.

Returns:

  • (String)

    a string denoting whether or not the pet is good with dogs



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#good_with_kidsString

Returns a string denoting whether or not the pet is good with kids.

Returns:

  • (String)

    a string denoting whether or not the pet is good with kids



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#housetrainedString

Returns a string denoting whether or not the pet is housetrained.

Returns:

  • (String)

    a string denoting whether or not the pet is housetrained



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#idString

Returns the AdoptAPet identifier for the pet.

Returns:

  • (String)

    the AdoptAPet identifier for the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#nameString

Returns the name of the pet.

Returns:

  • (String)

    the name of the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#pet_codeString

Returns the shelter/organization identifier for the pet.

Returns:

  • (String)

    the shelter/organization identifier for the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#photosArray<Photo>

Returns a set of photos for the pet.

Returns:

  • (Array<Photo>)

    a set of photos for the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#primary_breedString

Returns a description of the pet’s primary breed.

Returns:

  • (String)

    a description of the pet’s primary breed



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#purebredString

Returns a string denoting whether or not the pet is purebred.

Returns:

  • (String)

    a string denoting whether or not the pet is purebred



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#secondary_breedString

Returns a description of the pet’s secondary breed.

Returns:

  • (String)

    a description of the pet’s secondary breed



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#sexString

Returns the pet’s gender.

Returns:

  • (String)

    the pet’s gender



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#shots_currentString

Returns a string denoting whether or not the pet is current with their shots.

Returns:

  • (String)

    a string denoting whether or not the pet is current with their shots



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#sizeString

Returns a description of the size of the pet.

Returns:

  • (String)

    a description of the size of the pet



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#spayed_neuteredString

Returns a string denoting whether or not the pet is fixed.

Returns:

  • (String)

    a string denoting whether or not the pet is fixed



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#special_needsString

Returns a string denoting whether or not the pet has special needs.

Returns:

  • (String)

    a string denoting whether or not the pet has special needs



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#speciesString

Returns a description of the pet’s species.

Returns:

  • (String)

    a description of the pet’s species



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

#state_codeString

Returns the state where the pet resides.

Returns:

  • (String)

    the state where the pet resides



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/adopt_a_pet/pet.rb', line 54

class Pet
  attr_accessor :id,
                :pet_code,
                :age,
                :name,
                :size,
                :species,
                :primary_breed,
                :secondary_breed,
                :sex,
                :state_code,
                :city,
                :details_url,
                :photos,
                :act_quickly,
                :color,
                :special_needs,
                :purebred,
                :description,
                :good_with_dogs,
                :declawed,
                :spayed_neutered,
                :housetrained,
                :shots_current,
                :good_with_kids

  # Create a single instance of a Pet
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Pet] a new Pet
  def initialize(object) # rubocop:disable all
    extract(object, %w[pet_id],          'id')
    extract(object, %w[pet_code],        'pet_code')
    extract(object, %w[age],             'age')
    extract(object, %w[sex],             'sex')
    extract(object, %w[size],            'size')
    extract(object, %w[species],         'species')
    extract(object, %w[act_quickly],     'act_quickly')
    extract(object, %w[color],           'color')
    extract(object, %w[special_needs],   'special_needs')
    extract(object, %w[purebred],        'purebred')
    extract(object, %w[description],     'description')
    extract(object, %w[good_with_dogs],  'good_with_dogs')
    extract(object, %w[declawed],        'declawed')
    extract(object, %w[spayed_neutered], 'spayed_neutered')
    extract(object, %w[housetrained],    'housetrained')
    extract(object, %w[shots_current],   'shots_current')
    extract(object, %w[good_with_kids],  'good_with_kids')
    extract(object, %w[primary_breed],   'primary_breed')
    extract(object, %w[secondary_breed], 'secondary_breed')
    extract(object, %w[addr_state_code], 'state_code')
    extract(object, %w[addr_city],       'city')
    extract(object, %w[name pet_name],   'name')
    extract(object, %w[details_url pet_details_url], 'details_url')
    self.photos = ResponseHelper.extract_photos(object)
  end

  # Create multiple instances of Pet with one response
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  #
  # @return [Array<Pet>] Initialize a collection of Pets
  def self.multiple(object)
    pets = []

    object.dig('pets').each do |pet|
      pets = pets.push(Pet.new(pet))
    end

    pets
  end

  # Extract a value from a hash, and store it in an object key
  # @author Stephen Dolan
  #
  # @param [Hash] object a JSON response object from the Adopt-A-Pet API
  # @param [Array<String>] from_keys an array of keys to try and extract a value from
  # @param [String] to_key the name of the key to store the value in on the Pet
  #
  # @return [void]
  def extract(object, from_keys, to_key)
    response_item = nil

    # For each source key:
    # - Search for a value in the object
    from_keys&.each do |source|
      response_item = object.dig(source) unless object.dig(source).nil?
    end

    # Set the Pet attribute at to_key to the object value
    send("#{to_key}=", response_item)
  end

  # Class for Adopt-A-Pet Pet API response object helpers
  # @author Stephen Dolan
  class ResponseHelper
    # Extracts photos from a hash and pushes them into the Pet's photos
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    #
    # @return [Array<Pet::Photo>] an array of Pet Photos
    def self.extract_photos(object)
      photos = []

      # Get the various photos that could be returned for a pet
      photos = get_results_photo(object, photos)
      photos = get_large_results_photo(object, photos)
      get_other_photos(object, photos)
    end

    # Pull a results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_results_photo(object, photos)
      unless object.dig('results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('results_photo_height'),
            object.dig('results_photo_width'),
            object.dig('results_photo_url')
          )
        )
      end

      photos
    end

    # Pull a large results photo, if it exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_large_results_photo(object, photos)
      unless object.dig('large_results_photo_url').nil?
        photos = photos.push(
          original: Photo.new(
            object.dig('large_results_photo_height'),
            object.dig('large_results_photo_width'),
            object.dig('large_results_photo_url')
          )
        )
      end

      photos
    end

    # Pull any additional photos, if they exists in the API return object
    # @author Stephen Dolan
    #
    # @param [Hash] object a JSON response object from the Adopt-A-Pet API
    # @param [Array<Pet::Photo>] photos the current collection of Pet Photos
    #
    # @return [Array<Pet::Photo>] a (possibly expanded) array of Pet Photos
    def self.get_other_photos(object, photos)
      if (image_objects = object.dig('images'))
        image_objects.each do |image|
          photos = photos.push(
            original: Photo.new(
              image.dig('original_height'),
              image.dig('original_width'),
              image.dig('original_url')
            ),
            thumbnail: Photo.new(
              image.dig('thumbnail_height'),
              image.dig('thumbnail_width'),
              image.dig('thumbnail_url')
            )
          )
        end
      end

      photos
    end
  end

  # Class for Adopt-A-Pet Pet Photos
  # @author Stephen Dolan
  #
  # @!attribute height
  #   @return [Integer] the height of the Photo
  # @!attribute width
  #   @return [Integer] the width of the Photo
  # @!attribute url
  #   @return [String] a URL where you can view the Photo
  class Photo
    attr_accessor :height, :width, :url

    # Create a single instance of a Pet Photo
    # @author Stephen Dolan
    #
    # @param [Integer] height the height of the photo
    # @param [Integer] width the width of the Photo
    # @param [String] url a URL where you can view the photo
    #
    # @return [Pet::Photo] a new Pet Photo
    #
    # @example Create a new Photo
    #   my_photo = Pet::Photo.new(100, 100, 'images.com/my_image')
    #   height = my_photo.height
    def initialize(height, width, url)
      self.height  = height
      self.width   = width
      self.url     = url
    end
  end
end

Class Method Details

.multiple(object) ⇒ Array<Pet>

Create multiple instances of Pet with one response

Parameters:

  • object (Hash)

    a JSON response object from the Adopt-A-Pet API

Returns:

  • (Array<Pet>)

    Initialize a collection of Pets

Author:

  • Stephen Dolan



119
120
121
122
123
124
125
126
127
# File 'lib/adopt_a_pet/pet.rb', line 119

def self.multiple(object)
  pets = []

  object.dig('pets').each do |pet|
    pets = pets.push(Pet.new(pet))
  end

  pets
end

Instance Method Details

#extract(object, from_keys, to_key) ⇒ void

This method returns an undefined value.

Extract a value from a hash, and store it in an object key

Parameters:

  • object (Hash)

    a JSON response object from the Adopt-A-Pet API

  • from_keys (Array<String>)

    an array of keys to try and extract a value from

  • to_key (String)

    the name of the key to store the value in on the Pet

Author:

  • Stephen Dolan



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/adopt_a_pet/pet.rb', line 137

def extract(object, from_keys, to_key)
  response_item = nil

  # For each source key:
  # - Search for a value in the object
  from_keys&.each do |source|
    response_item = object.dig(source) unless object.dig(source).nil?
  end

  # Set the Pet attribute at to_key to the object value
  send("#{to_key}=", response_item)
end