Class: Property

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

Instance Method Summary collapse

Methods included from MLS::Avatar

#avatar_url

Instance Method Details

#addressObject



28
29
30
# File 'lib/mls/property.rb', line 28

def address
  addresses.find(&:primary)
end

#automated_descriptionObject



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

def automated_description
  external_data['narrativescience.com']
end

#city_regionObject



107
108
109
110
# File 'lib/mls/property.rb', line 107

def city_region
  return @city_region if defined? @city_region
  @city_region = fetch_region(:type => "City")
end

#closest_regionObject



93
94
95
96
97
98
# File 'lib/mls/property.rb', line 93

def closest_region
  region = neighborhood_region
  region ||= city_region
  region ||= market
  region
end

#contactObject



23
24
25
26
# File 'lib/mls/property.rb', line 23

def contact
  @contact ||= listings.where(leased_at: nil, authorized: true, type: ['Lease', 'Sublease'])
          .order(size: :desc).first.try(:contact)
end

#fetch_region(params) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/mls/property.rb', line 122

def fetch_region(params)
  if regions.loaded?
    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| r[params[0][0]] == params[0][1]}
    end
  else
    regions.where(params).first
  end
end

#flagshipObject



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

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

#internet_providersObject



44
45
46
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
# File 'lib/mls/property.rb', line 44

def internet_providers
  data = []
  
  if external_data['broadbandmap.gov']
    if external_data['broadbandmap.gov']['wirelineServices']
      external_data['broadbandmap.gov']['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 '1 Gb/s+'
           else 'Unknown'
           end
         }

         data << {
           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
    end
  end

  data
end

#latitudeObject



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

def latitude
  location.y
end

#longitudeObject



32
33
34
# File 'lib/mls/property.rb', line 32

def longitude
  location.x
end

#marketObject



112
113
114
115
# File 'lib/mls/property.rb', line 112

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

#neighborhood_regionObject



100
101
102
103
104
105
# File 'lib/mls/property.rb', line 100

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

#photosObject



19
20
21
# File 'lib/mls/property.rb', line 19

def photos
  image_orderings.sort_by(&:order).map(&:image)
end