Class: Listing
- Inherits:
-
MLS::Model
- Object
- ActiveRecord::Base
- MLS::Model
- Listing
- Includes:
- MLS::Avatar, MLS::Slugger
- Defined in:
- lib/mls/models/listing.rb
Constant Summary collapse
- UNIT_TYPES =
%w(unit floor building)
- FLOORS =
["Basement", "Mezzanine", "Penthouse", "Concourse", "Lower Level"] + (1..150).to_a
- TYPES =
%w(Sale Lease Sublease)
- TERMS =
['Full Service', 'Net Lease', 'NN', 'NNN', 'Absolute NNN', 'Gross Lease', 'Modified Gross', 'Industrial Gross', 'Absolute Gross', 'Ground Lease', 'Other']
- SALE_TERMS =
['Cash to Seller', 'Purchase Money Mtg.', 'Owner Financing', 'Build-to-Suit', 'Sale/Leaseback', 'Other']
- RATE_UNITS =
{ '/sqft/yr' => 'rate_per_sqft_per_year', '/sqft/mo' => 'rate_per_sqft_per_month', '/mo' => 'rate_per_month', '/yr' => 'rate_per_year', }
- TERM_UNITS =
['years', 'months']
- AMENITIES =
%W(kitchen showers outdoor_space reception turnkey build_to_suit furniture natural_light high_ceilings plug_and_play additional_storage storefront offices conference_rooms bathrooms)
Instance Method Summary collapse
- #contacts ⇒ Object
- #is_elite? ⇒ Boolean
- #latitude ⇒ Object
- #lead_contacts ⇒ Object
-
#lease? ⇒ Boolean
TODO: test me.
- #longitude ⇒ Object
- #name ⇒ Object
- #premium_property? ⇒ Boolean
- #rate(units = nil) ⇒ Object
- #regions ⇒ Object
- #sale? ⇒ Boolean
- #status ⇒ Object
-
#sublease? ⇒ Boolean
TODO: test me.
Instance Method Details
#contacts ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/mls/models/listing.rb', line 48 def contacts if ownerships.loaded? @contacts ||= ownerships.select{|o| o.receives_inquiries }.map(&:account) else @contacts ||= ownerships.eager_load(:account).filter(:receives_inquiries => true).map(&:account) end end |
#is_elite? ⇒ Boolean
40 41 42 |
# File 'lib/mls/models/listing.rb', line 40 def is_elite? ((property.elite_account_ids || []) & accounts.map(&:id)).length > 0 end |
#latitude ⇒ Object
135 136 137 |
# File 'lib/mls/models/listing.rb', line 135 def latitude location.y end |
#lead_contacts ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/mls/models/listing.rb', line 56 def lead_contacts if ownerships.loaded? @lead_contacts ||= ownerships.select{|o| o.lead}.map(&:account) else @lead_contacts ||= ownerships.eager_load(:account).filter(:lead => true).map(&:account) end end |
#lease? ⇒ Boolean
TODO: test me
139 140 141 |
# File 'lib/mls/models/listing.rb', line 139 def lease? # TODO: test me type == 'Lease' end |
#longitude ⇒ Object
131 132 133 |
# File 'lib/mls/models/listing.rb', line 131 def longitude location.x end |
#name ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/mls/models/listing.rb', line 151 def name return "New Listing" if !self.id name = "" if self.unit_type == "building" name += "Entire Building" else name = "Unit #{self.unit}" if self.unit.present? name += " (" if self.unit.present? && self.floor.present? name += "Floor #{self.floor}" if self.floor.present? name += ")" if self.unit.present? && self.floor.present? end name = "Space" if name.blank? name end |
#premium_property? ⇒ Boolean
44 45 46 |
# File 'lib/mls/models/listing.rb', line 44 def premium_property? Subscription.filter(started_at: true, ends_at: false, type: "premium", subject_type: "Property", subject_id: self.property_id).count > 0 end |
#rate(units = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/mls/models/listing.rb', line 64 def rate(units=nil) return nil if !read_attribute(:rate) units ||= rate_units price = if rate_units == '/sqft/mo' if units == '/sqft/mo' read_attribute(:rate) elsif units == '/sqft/yr' read_attribute(:rate) * 12.0 elsif units == '/mo' read_attribute(:rate) * size elsif units == '/yr' read_attribute(:rate) * size * 12.0 else raise "Invalid rate conversion (#{rate_units} => #{units})" end elsif rate_units == '/sqft/yr' if units == '/sqft/mo' read_attribute(:rate) / 12.0 elsif units == '/sqft/yr' read_attribute(:rate) elsif units == '/mo' (read_attribute(:rate) * size) / 12.0 elsif units == '/yr' read_attribute(:rate) * size else raise "Invalid rate conversion (#{rate_units} => #{units})" end elsif rate_units == '/mo' if units == '/sqft/mo' read_attribute(:rate) / size.to_f elsif units == '/sqft/yr' (read_attribute(:rate) * 12) / size.to_f elsif units == '/mo' read_attribute(:rate) elsif units == '/yr' read_attribute(:rate) * 12 else raise "Invalid rate conversion (#{rate_units} => #{units})" end elsif rate_units == '/yr' if units == '/sqft/mo' (read_attribute(:rate) / 12.0) / size.to_f elsif units == '/sqft/yr' read_attribute(:rate) / size.to_f elsif units == '/mo' read_attribute(:rate) / 12.0 elsif units == '/yr' read_attribute(:rate) else raise "Invalid rate conversion (#{rate_units} => #{units})" end else read_attribute(:rate) end price.round(2) end |
#regions ⇒ Object
127 128 129 |
# File 'lib/mls/models/listing.rb', line 127 def regions Region.where(:id => self.region_ids) end |
#sale? ⇒ Boolean
147 148 149 |
# File 'lib/mls/models/listing.rb', line 147 def sale? type == 'Sale' end |
#status ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mls/models/listing.rb', line 166 def status if self.leased_at "Leased" elsif self.archived "Deleted" elsif self.touched_at < 180.days.ago "Expired" else "Active" end end |
#sublease? ⇒ Boolean
TODO: test me
143 144 145 |
# File 'lib/mls/models/listing.rb', line 143 def sublease? # TODO: test me type == 'Sublease' end |