Sha256: 366a44390e17f3a62a8d87c2b649259d1b8c158e3c0b24cfc6eb9c25e24d2234
Contents?: true
Size: 1.45 KB
Versions: 5
Compression:
Stored size: 1.45 KB
Contents
module Petfinder class Pet extend JsonMapper json_attributes "name", "breed", "age", "size", "id", "description", "shelter_id" attr_reader :attributes, :contact_info def initialize pet_hash @attributes = pet_hash @contact_info = contact end def photos parse_photos if @photos.nil? @photos end private def contact class << self json_attributes "phone", "state", "email", "city", "zip", "fax", "address1" end end def parse_photos @photos = [] @attributes["media"]["photos"]["photo"].each do |photo| add_photo photo, photo["$t"] end end def add_photo photo, url size = photo["@size"] photo = set_photo photo case size when "x" photo.large = url when "pn" photo.medium = url when "fpm" photo.small = url when "pnt" photo.tiny = url end @photos << photo unless @photos.find_index photo end def set_photo photo @photos.each do |existing_photo| if photo["@id"] == existing_photo.id return existing_photo end end Photo.new photo end class Photo attr_accessor :large, :medium, :small, :thumbnail, :tiny attr_reader :id, :attributes def initialize attributes @attributes = attributes @id = attributes["@id"] end end end end
Version data entries
5 entries across 5 versions & 1 rubygems