Class: Listing

Inherits:
MLS::Model show all
Includes:
MLS::Avatar, MLS::Slugger
Defined in:
lib/mls/listing.rb

Constant Summary collapse

LEASE_STATES =
%w(listed leased)
SPACE_TYPES =
%w(unit floor building)
TYPES =
%w(Sale Lease Sublease CoworkingSpace)
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 patio reception ready_to_move_in furniture natural_light high_ceilings)

Instance Method Summary collapse

Methods included from MLS::Avatar

#avatar_url

Methods included from MLS::Slugger

#to_param

Instance Method Details

#contactObject Also known as: default_contact



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

def contact
  @contact ||= agents.first
end

#coworking?Boolean

TODO: test me

Returns:

  • (Boolean)


125
126
127
# File 'lib/mls/listing.rb', line 125

def coworking? # TODO: test me
  type == 'CoworkingSpace'
end

#lease?Boolean

TODO: test me

Returns:

  • (Boolean)


117
118
119
# File 'lib/mls/listing.rb', line 117

def lease? # TODO: test me
  type == 'Lease'
end

#nameObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/mls/listing.rb', line 133

def name
  return read_attribute(:name) if read_attribute(:name)

  case space_type
  when 'unit'
    if unit
      "Unit #{unit}"
    elsif floor
      "#{floor.ordinalize} Floor Unit"
    else
      "Unit Lease"
    end
  when 'building'
    "Entire Building"
  when 'floor'
    if floor
      "#{floor.ordinalize} Floor"
    elsif unit
      "Unit #{unit}"
    else
      "Floor Lease"
    end
  end
end

#rate(units = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
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
# File 'lib/mls/listing.rb', line 54

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

#sale?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/mls/listing.rb', line 129

def sale?
  type == 'Sale'
end

#sublease?Boolean

TODO: test me

Returns:

  • (Boolean)


121
122
123
# File 'lib/mls/listing.rb', line 121

def sublease? # TODO: test me
  type == 'Sublease'
end