Sha256: ac3fe3d6a0c33e6ec9e97a310ab00b4702f72ca5535affadce2a79d446a6d2da

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

module YouGotListed
  class Complex

    attr_accessor :client

    def initialize(listing, client)
      listing.each do |key, value|
        self.instance_variable_set("@#{key}", value)
        self.class.send(:attr_reader, key)
      end
      self.client = client
    end

    def properties
      @cached_properties ||= begin
        props = []
        if defined?(self.listings) && !self.listings.blank?
          if self.listings.listing.is_a?(Array)
            self.listings.listing.each do |listing|
              listing = listing.merge(find_address(listing.address_id))
              props << YouGotListed::Listing.new(listing, self.client)
            end
          else
            listing = self.listings.listing.merge(find_address(self.listings.listing.address_id))
            props << YouGotListed::Listing.new(listing, self.client)
          end
        end
        props
      end
    end

    def pictures
      self.photos.photo unless self.photos.blank? || self.photos.photo.blank?
    end

    def find_address(address_id)
      if addresses.address.is_a?(Array)
        addresses.address.find{|address| address.id == address_id}
      else
        addresses.address
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
you_got_listed-0.6.4 lib/you_got_listed/complex.rb