Class: Listing

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

Constant Summary collapse

SPACE_TYPES =
%w(unit floor building)
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)

Instance Method Summary collapse

Instance Method Details

#contactObject

has_many :favoritizations, :foreign_key => :favorite_id has_many :accounts, :through => :favoritizations has_many :inquiries, :as => :subject, :inverse_of => :subject has_many :agencies, -> { order(‘“order”’) }, :dependent => :destroy, :inverse_of => :subject, :as => :subject has_many :agents, -> { order(‘agencies.order’) }, :through => :agencies, :inverse_of => :listings, :source => :agent has_many :lead_listings, :dependent => :delete_all



43
44
45
# File 'lib/mls/listing.rb', line 43

def contact
  @contact ||= agents.first
end

#lease?Boolean

TODO: test me

Returns:

  • (Boolean)


110
111
112
# File 'lib/mls/listing.rb', line 110

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

#nameObject



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

def name
  return read_attribute(:name) if read_attribute(:name)
  unit.name
end

#rate(units = nil) ⇒ Object



47
48
49
50
51
52
53
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
# File 'lib/mls/listing.rb', line 47

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)


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

def sale?
  type == 'Sale'
end

#sublease?Boolean

TODO: test me

Returns:

  • (Boolean)


114
115
116
# File 'lib/mls/listing.rb', line 114

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