Class: Property

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

Constant Summary collapse

LEED_CERTIFICATIONS =
%w(None Certified Silver Gold Platinum)
AMENITIES =
%W(parking_garage lobby_attendant gym common_kitchen
common_bike_storage onsite_parking key_card_access freight_elevator
ada_accessible on_site_security
elevators close_highway close_public_transit close_points_of_interest
parking_ratio number_of_buildings)
CONSTRUCTION_TYPES =
%w(brick steel concrete masonry tiltwall wood glass)

Instance Method Summary collapse

Instance Method Details

#addressObject



40
41
42
# File 'lib/mls/models/property.rb', line 40

def address
  addresses.find(&:primary)
end

#city_regionObject



142
143
144
145
# File 'lib/mls/models/property.rb', line 142

def city_region
  return @city_region if defined? @city_region
  @city_region = fetch_region(:type => Region::CITY_TYPES)
end

#closest_regionObject



127
128
129
130
131
132
133
# File 'lib/mls/models/property.rb', line 127

def closest_region
  region = neighborhood_region
  region ||= city_region
  region ||= market
  region ||= regions.filter(depth: true).select{ |r| r.type != "Zip Code Tabulation Area" }.sort_by(&:depth).reverse.first
  region
end

#contactsObject



35
36
37
38
# File 'lib/mls/models/property.rb', line 35

def contacts
  @contact ||= listings.eager_load(:accounts => [:email_addresses, :phones, :organization]).filter(leased_at: nil, authorized: true, type: ['Lease', 'Sublease'], :touched_at => {:gte => 180.days.ago})
          .order(size: :desc).first.try(:contacts)
end

#display_descriptionObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mls/models/property.rb', line 58

def display_description
  return description if description.present?
  return unless description_data_entry
  # If has bullets
  if description_data_entry && description_data_entry.split("\n").all? { |x| ['-','*', ''].include?(x.strip[0]) }
    <<~MD
    ##Features
    #{description_data_entry}
    MD
  else description_data_entry
    show_amenities = amenities.select{ |k,v| v }
    <<~MD
    #{description_data_entry}
    #{"This building's amenities include " + show_amenities.map {|key, v| key.to_s.humanize.downcase }.to_sentence + "."}
    MD
  end
end

#fetch_region(params) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/mls/models/property.rb', line 172

def fetch_region(params)
  params = params.map{|k,v| [k, v]}
  if params[0][0] == :query
    regions.to_a.find{|r| r.name == params[0][1]}
  else
    regions.to_a.find{|r|
      if params[0][1].is_a? Array
        params[0][1].include? (r[params[0][0]])
      else
        r[params[0][0]] == params[0][1]
      end
    }
  end
end

#flagshipObject



167
168
169
170
# File 'lib/mls/models/property.rb', line 167

def flagship
  return @flagship if defined? @flagship
  @flagship = fetch_region(:is_flagship => true)
end

#human_breadcrumbsObject



157
158
159
160
161
162
163
164
165
# File 'lib/mls/models/property.rb', line 157

def human_breadcrumbs
  [
    neighborhood.present? ? neighborhood : neighborhood_region&.name,
    city.present? ? city : (city_region&.name || regions.select{|r|
      r.depth && r.depth >= 3
    }.first&.name),
    state.present? ? state : state_region&.slug&.split("/")&.last&.upcase
  ].compact
end

#internet_providersObject



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/property.rb', line 76

def internet_providers
  idata = []
  
  datum = data.select{|d| d.source == "broadbandmap.gov"}.first.try(:datum) if data.loaded?
  datum ||= data.where(source: 'broadbandmap.gov').first.try(:datum)
  return idata unless datum && datum['wirelineServices']

  datum['wirelineServices'].sort_by{|p| p['technologies'].sort_by{|t| t['maximumAdvertisedDownloadSpeed']}.reverse.first['maximumAdvertisedDownloadSpeed']}.reverse.each do |provider|
     tech = provider['technologies'].sort_by{|t| t['maximumAdvertisedDownloadSpeed']}.reverse.first
     speedcase = -> (speedCode) {
       case speedCode
       when 1 then '200 kbps'
       when 2 then '768 kbps'
       when 3 then '1.5 Mb/s'
       when 4 then '3 Mb/s'
       when 5 then '6 Mb/s'
       when 6 then '10 Mb/s'
       when 7 then '25 Mb/s'
       when 8 then '50 Mb/s'
       when 9 then '100 Mb/s'
       when 10 then '1 Gb/s'
       when 11 then '10 Gb/s'
       when 12 then '100 Gb/s'
       when 13 then '100 Gb/s+'
       else 'Unknown'
       end
     }

     idata << {
       provider_name: provider['doingBusinessAs'] || provider['providerName'],
       provider_url: provider['providerURL'],
       technology: case tech['technologyCode']
         when 10 then 'DSL'
         when 20 then 'DSL'
         when 30 then 'Copper Wireline'
         when 40 then 'Cable'
         when 41 then 'Cable'
         when 50 then 'Fiber'
         when 90 then 'Power Line'
         else 'Other'
         end,
       bandwidth: {
         up: speedcase.call(tech['maximumAdvertisedUploadSpeed']),
         down: speedcase.call(tech['maximumAdvertisedDownloadSpeed'])
       }
     }
  end

  idata
end

#is_elite_for_account_ids?(*account_ids) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/mls/models/property.rb', line 52

def (*)
  return false unless self. && self..length > 0
   = Array().flatten
  (self. & ).length > 0
end

#latitudeObject



48
49
50
# File 'lib/mls/models/property.rb', line 48

def latitude
  location.y
end

#longitudeObject



44
45
46
# File 'lib/mls/models/property.rb', line 44

def longitude
  location.x
end

#marketObject



152
153
154
155
# File 'lib/mls/models/property.rb', line 152

def market
  return @market if defined? @market
  @market = fetch_region(:is_market => true)
end

#neighborhood_regionObject



135
136
137
138
139
140
# File 'lib/mls/models/property.rb', line 135

def neighborhood_region
  return @neighborhood_region if defined? @neighborhood_region
  params = {:query => neighborhood} if neighborhood
  params ||= {:type => "Neighborhood"}
  @neighborhood_region = fetch_region(params)
end

#state_regionObject



147
148
149
150
# File 'lib/mls/models/property.rb', line 147

def state_region
  return @state_region if defined? @state_region
  @state_region = fetch_region(:type => Region::STATE_TYPES)
end