Sha256: 022d44202d2d50f0f769522f713745569d8bb08d59cae5f35633ea2e4a0cf5fb

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 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(:define_method, key, proc{self.instance_variable_get("@#{key}")})
      end
      self.client = client
    end
    
    def properties
      return [] if self.listings.blank?
      props = []
      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(listing.address_id))
        props << YouGotListed::Listing.new(listing, self.client)
      end
      props
    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

10 entries across 10 versions & 1 rubygems

Version Path
you_got_listed-0.3.3 lib/you_got_listed/complex.rb
you_got_listed-0.3.2 lib/you_got_listed/complex.rb
you_got_listed-0.3.1 lib/you_got_listed/complex.rb
you_got_listed-0.3.0 lib/you_got_listed/complex.rb
you_got_listed-0.2.5 lib/you_got_listed/complex.rb
you_got_listed-0.2.4 lib/you_got_listed/complex.rb
you_got_listed-0.2.3 lib/you_got_listed/complex.rb
you_got_listed-0.2.2 lib/you_got_listed/complex.rb
you_got_listed-0.2.1 lib/you_got_listed/complex.rb
you_got_listed-0.2.0 lib/you_got_listed/complex.rb