class Pet
Attributes
age[RW]
breeds[RW]
contact[RW]
description[RW]
images[RW]
last_update[RW]
name[RW]
options[RW]
petfinder_id[RW]
sex[RW]
shelter_id[RW]
shelter_pet_id[RW]
size[RW]
status[RW]
Public Class Methods
make_pet(result)
click to toggle source
# File lib/petsearch/pet.rb, line 54 def self.make_pet(result) @@pets = [] return [{'code' => '999', 'message' => 'Cannot Make Pet. Bad parameters or no results'}] if ((!result[0]['code'].nil? || result[0]['petfinder']['header']['status']['code']['$t'].to_i != 100) == true) if result[0]['petfinder']['lastOffset']['$t'].to_i > 1 petresult = result[0]['petfinder']['pets']['pet'] elsif result[0]['petfinder']['lastOffset']['$t'].to_i == 1 petresult = [[]] petresult[0] << result[0]['petfinder']['pets']['pet'] petresult = petresult[0] else end resultsize = result[0]['petfinder']['lastOffset']['$t'].to_i petresult.each do |pet| p = Pet.new if (pet['options']['option'].class == Hash) p.options << pet['options']['option']['$t'] elsif (pet['options']['option'].class == Array) p.options = pet['options']['option'].map { |t| t['$t'] } else p.options = [] end if (pet['breeds']['breed'].class == Hash) p.breeds << pet['breeds']['breed']['$t'] elsif (pet['breeds']['breed'].class == Array) p.breeds = pet['breeds']['breed'].map { |t| t['$t']} else p.breeds = [] end p.shelter_pet_id = pet['shelterPetId'] ? pet['shelterPetId']['$t'] : "" p.status = pet['status']['$t'] p.name = pet['name']['$t'] p.contact[:email] = pet['contact']['email']['$t'] p.contact[:zip] = pet['contact']['zip']['$t'] p.contact[:city] = pet['contact']['city']['$t'] p.contact[:fax] = pet['contact']['fax']['$t'] p.contact[:address1] = pet['contact']['address1']['$t'] p.contact[:phone] = pet['contact']['phone']['$t'] p.contact[:state] = pet['contact']['state']['$t'] p.description=HTMLEntities.new.decode(ActionView::Base.full_sanitizer.sanitize(pet['description']['$t'])) p.sex = pet['sex']['$t'] p.shelter_id = pet['shelterId']['$t'] p.size = pet['size']['$t'] p.age = pet['age']['$t'] p.last_update = Date.parse((pet['lastUpdate']['$t'].split('T'))[0]) if (pet['media']['photos'].class == Array || pet['media']['photos'].class==Hash) p.images = pet['media']['photos']['photo'].map { |photo| photo['$t'] } else p.images = [] end p.petfinder_id = pet['id']['$t'] @@pets << p end return @@pets end
make_search(options)
click to toggle source
(?<=&)(d{5})(?=&)
RAILS ONLY - FOR SEARCHING WITH URLS
# File lib/petsearch/pet.rb, line 33 def self.make_search(options) animal = options.match(/animal=(.*?)&/).nil? ? "ERROR" : options.match(/animal=(.*?)&/)[1] br=options.match(/&breeds=(.*?)&/).nil? ? [] : options.match(/&breeds=(.*?)&/)[1] breeds = br.split(',') unless br.empty? offset = options.match(/&off(.*?)&/).nil? ? "" : options.match(/&off(.*?)&/)[1] count = options.match(/&ct(.*?)&/).nil? ? "" : options.match(/&ct(.*?)&/)[1] sex = options.match(/&sex=(.*?)&/).nil? ? "" : options.match(/&sex=(.*?)&/)[1] location = options.match(/(?<=\&)(\d{5})(?=\&)/).nil? ? "" : options.match(/(?<=\&)(\d{5})(?=\&)/)[1] if options.match(/(?=)([Ss]m|[Mm]dm|[Ll]rg|[Xx]l)/).nil? size = "" elsif options.match(/(?=)([Ss]m|[Mm]dm|[Ll]rg|[Xx]l)/).length > 3 size = options.match(/(?=)([Ss]m|[Mm]dm|[Ll]rg|[Xx]l)/)[2] else size = options.match(/(?=)([Ss]m|[Mm]dm|[Ll]rg|[Xx]l)/)[1] end PetSearch.init_options("#{animal}", "#{location}", "ct#{count}", "#{size}", "#{sex}", "off#{offset}") PetSearch.options[:breeds] = breeds.nil? ? [] : breeds result = PetSearch.search make_pet(result) end
new()
click to toggle source
# File lib/petsearch/pet.rb, line 11 def initialize @name = '' @age = '' @sex = '' @size = '' @petfinder_id = '' @shelter_id = '' @images = [] @breeds = [] @contact = {} @status = '' @description = '' @last_update = '' @options = [] @shelter_pet_id = {} end
pets()
click to toggle source
# File lib/petsearch/pet.rb, line 28 def self.pets @@pets end