Class: AdoptAPet::Pet
- Inherits:
-
Object
- Object
- AdoptAPet::Pet
- Defined in:
- lib/adopt_a_pet/pet.rb
Overview
Base class for Adopt-A-Pet Pet objects
Defined Under Namespace
Classes: Photo, ResponseHelper
Instance Attribute Summary collapse
-
#act_quickly ⇒ String
A string denoting whether action is required quickly for adoption.
-
#age ⇒ String
A description of the age of the pet.
-
#city ⇒ String
The city where the pet resides.
-
#color ⇒ String
A description of the color of the pet.
-
#declawed ⇒ String
A string denoting whether or not the pet is declawed.
-
#description ⇒ String
A description of the pet.
-
#details_url ⇒ String
A link to the details page for the pet on Adopt-A-Pet.
-
#good_with_dogs ⇒ String
A string denoting whether or not the pet is good with dogs.
-
#good_with_kids ⇒ String
A string denoting whether or not the pet is good with kids.
-
#housetrained ⇒ String
A string denoting whether or not the pet is housetrained.
-
#id ⇒ String
The AdoptAPet identifier for the pet.
-
#name ⇒ String
The name of the pet.
-
#pet_code ⇒ String
The shelter/organization identifier for the pet.
-
#photos ⇒ Array<Photo>
A set of photos for the pet.
-
#primary_breed ⇒ String
A description of the pet’s primary breed.
-
#purebred ⇒ String
A string denoting whether or not the pet is purebred.
-
#secondary_breed ⇒ String
A description of the pet’s secondary breed.
-
#sex ⇒ String
The pet’s gender.
-
#shots_current ⇒ String
A string denoting whether or not the pet is current with their shots.
-
#size ⇒ String
A description of the size of the pet.
-
#spayed_neutered ⇒ String
A string denoting whether or not the pet is fixed.
-
#special_needs ⇒ String
A string denoting whether or not the pet has special needs.
-
#species ⇒ String
A description of the pet’s species.
-
#state_code ⇒ String
The state where the pet resides.
Class Method Summary collapse
-
.multiple(object) ⇒ Array<Pet>
Create multiple instances of Pet with one response.
Instance Method Summary collapse
-
#extract(object, from_keys, to_key) ⇒ void
Extract a value from a hash, and store it in an object key.
-
#initialize(object) ⇒ Pet
constructor
Create a single instance of a Pet.
Constructor Details
#initialize(object) ⇒ Pet
Create a single instance of a Pet
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_quickly ⇒ String
Returns 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 |
#age ⇒ String
Returns 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 |
#city ⇒ String
Returns 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 |
#color ⇒ String
Returns 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 |
#declawed ⇒ String
Returns 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 |
#description ⇒ String
Returns 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_url ⇒ String
Returns 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_dogs ⇒ String
Returns 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_kids ⇒ String
Returns 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 |
#housetrained ⇒ String
Returns 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 |
#id ⇒ String
Returns 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 |
#name ⇒ String
Returns 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_code ⇒ String
Returns 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 |
#photos ⇒ Array<Photo>
Returns 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_breed ⇒ String
Returns 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 |
#purebred ⇒ String
Returns 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_breed ⇒ String
Returns 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 |
#sex ⇒ String
Returns 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_current ⇒ String
Returns 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 |
#size ⇒ String
Returns 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_neutered ⇒ String
Returns 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_needs ⇒ String
Returns 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 |
#species ⇒ String
Returns 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_code ⇒ String
Returns 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
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
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 |