Class: YouGotListed::Listing

Inherits:
Object
  • Object
show all
Defined in:
lib/you_got_listed/listing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listing, client) ⇒ Listing

Returns a new instance of Listing.



6
7
8
9
10
11
12
13
14
# File 'lib/you_got_listed/listing.rb', line 6

def initialize(listing, client)
  listing.each do |key, value|
    self.instance_variable_set("@#{key}", value)
    unless ["latitude", "longitude"].include?(key)
      self.class.send(:attr_reader, key)
    end
  end
  self.client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/you_got_listed/listing.rb', line 4

def client
  @client
end

Instance Method Details

#city_neighborhoodObject



56
57
58
59
60
# File 'lib/you_got_listed/listing.rb', line 56

def city_neighborhood
  str = self.city
  str += ":#{neighborhood}" unless self.neighborhood.blank?
  str
end

#latitudeObject



74
75
76
# File 'lib/you_got_listed/listing.rb', line 74

def latitude
  @latitude.to_f unless @latitude.blank?
end

#longitudeObject



78
79
80
# File 'lib/you_got_listed/listing.rb', line 78

def longitude
  @longitude.to_f unless @longitude.blank?
end

#main_pictureObject



66
67
68
# File 'lib/you_got_listed/listing.rb', line 66

def main_picture
  pictures.first if pictures
end

#mls_listing?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/you_got_listed/listing.rb', line 70

def mls_listing?
  source && source == "MLS"
end

#picturesObject



62
63
64
# File 'lib/you_got_listed/listing.rb', line 62

def pictures
  (self.photos.photo.is_a?(Array) ? self.photos.photo : [self.photos.photo])  unless self.photos.blank? || self.photos.photo.blank?
end

#similar_listings(limit = 6, search_options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/you_got_listed/listing.rb', line 28

def similar_listings(limit = 6, search_options = {})
  criteria = similar_listings_criteria
  search_params = {
    :limit => limit + 1,
    :min_rent => criteria[:price_low],
    :max_rent => criteria[:price_high],
    :min_bed => criteria[:min_beds],
    :max_bed => criteria[:max_beds],
    :baths => [criteria[:min_baths], self.baths, criteria[:max_baths]].join(','),
    :city_neighborhood => self.city_neighborhood
  }.merge(search_options)
  @cached_similars ||= begin
    similar = []
    listings = YouGotListed::Listings.new(self.client)
    listings.search(search_params).properties.each do |prop|
      similar << prop unless prop.id == self.id
      break if similar.size == limit
    end
    similar
  end
end

#similar_listings_criteriaObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/you_got_listed/listing.rb', line 16

def similar_listings_criteria
  {
    :price_low => (self.price.to_i * 0.9).to_i,
    :price_high => (self.price.to_i * 1.1).to_i,
    :min_beds => ((self.beds.to_i - 1) <= 0 ? 0 : (self.beds.to_i - 1)),
    :max_beds => self.beds.to_i + 1,
    :min_baths => ((self.baths.to_i - 1) <= 0 ? 0 : (self.baths.to_i - 1)),
    :max_baths => self.baths.to_i + 1,
    :towns => self.city_neighborhood
  }
end

#town_neighborhoodObject



50
51
52
53
54
# File 'lib/you_got_listed/listing.rb', line 50

def town_neighborhood
  str = self.city
  str += " - #{neighborhood}" unless self.neighborhood.blank?
  str
end