Class: Rentjuicer::Listing

Inherits:
Object
  • Object
show all
Defined in:
lib/rentjuicer/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
# File 'lib/rentjuicer/listing.rb', line 6

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#courtesy_ofObject



89
90
91
# File 'lib/rentjuicer/listing.rb', line 89

def courtesy_of
  attribution_split[0] if mls_listing? && attribution_split && attribution_split[0]
end

#first_picObject



57
58
59
# File 'lib/rentjuicer/listing.rb', line 57

def first_pic
  main_pic[:fullsize] if main_pic
end

#idObject



49
50
51
# File 'lib/rentjuicer/listing.rb', line 49

def id
  rentjuice_id
end

#main_picObject



61
62
63
# File 'lib/rentjuicer/listing.rb', line 61

def main_pic
  @main_picture ||= sorted_photos.detect(lambda {return sorted_photos.first}) { |photo| photo[:main_photo] } if sorted_photos
end

#mls_disclaimerObject



85
86
87
# File 'lib/rentjuicer/listing.rb', line 85

def mls_disclaimer
  attribution_split[1].gsub('<br />', '') if mls_listing? && attribution_split && attribution_split[1]
end

#mls_listing?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rentjuicer/listing.rb', line 81

def mls_listing?
  source_type && source_type == "mls"
end

#neighborhood_nameObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rentjuicer/listing.rb', line 69

def neighborhood_name
  @neigh_name ||= begin
    unless neighborhoods.blank?
      if self.neighborhoods.first.is_a?(String)
        self.neighborhoods.first
      elsif self.neighborhoods.first.is_a?(Array)
        self.neighborhoods.first[1]
      end
    end
  end
end

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



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

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_beds => criteria[:min_beds],
    :max_beds => criteria[:max_beds],
    :min_baths => criteria[:min_baths],
    :max_baths => criteria[:max_baths],
    :neighborhoods => criteria[:towns]
  }.merge(search_options)
  @cached_similars ||= begin
    similar = []
    listings = Rentjuicer::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



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rentjuicer/listing.rb', line 14

def similar_listings_criteria
  {
    :price_low => self.rent.to_i * 0.9,
    :price_high => self.rent.to_i * 1.1,
    :min_beds => ((self.bedrooms.to_i - 1) <= 0 ? 0 : (self.bedrooms.to_i - 1)),
    :max_beds => self.bedrooms.to_i + 1,
    :min_baths => ((self.bathrooms.to_i - 1) <= 0 ? 0 : (self.bathrooms.to_i - 1)),
    :max_baths => self.bathrooms.to_i + 1,
    :towns => self.neighborhood_name
  }
end

#sorted_photosObject



65
66
67
# File 'lib/rentjuicer/listing.rb', line 65

def sorted_photos
  @sorted_pictures ||= self.photos.sort_by{|photo| photo[:sort_order].to_i} if photos
end

#thumb_picObject



53
54
55
# File 'lib/rentjuicer/listing.rb', line 53

def thumb_pic
  main_pic[:thumbnail] if main_pic
end