Class: MLS::Listing
Defined Under Namespace
Classes: Parser
Constant Summary
collapse
- WORKFLOW_STATES =
%w(visible processing invisible expired)
- LEASE_STATES =
%w(listed leased)
- TYPES =
%w(lease sublease coworking_space)
- SPACE_TYPES =
%w(unit floor building)
- LEASE_TERMS =
['Full Service', 'NNN', 'Modified Gross']
- RATE_UNITS =
['/sqft/yr', '/sqft/mo', '/mo', '/yr', '/desk/mo']
- USES =
["Office", "Creative", "Loft", "Medical Office", "Flex Space", "R&D", "Office Showroom", "Industrial", "Retail"]
- SOURCE_TYPES =
%w(website flyer)
- CHANNELS =
%w(excavator mls staircase broker_dashboard)
Instance Attribute Summary collapse
Attributes inherited from Resource
#errors, #persisted
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Resource
#==, #create!, inherited, #initialize, #new_record?, #persisted?, #properties, #properties_excluded_from_comparison, #properties_for_comparison, #save!, #set_default_values, #to_key, #update!, #update_attributes
Constructor Details
This class inherits a constructor from MLS::Resource
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def account
@account
end
|
#address ⇒ Object
Returns the value of attribute address.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def address
@address
end
|
#agents ⇒ Object
Returns the value of attribute agents.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def agents
@agents
end
|
#floorplan ⇒ Object
Returns the value of attribute floorplan.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def floorplan
@floorplan
end
|
#flyer ⇒ Object
Returns the value of attribute flyer.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def flyer
@flyer
end
|
#photos ⇒ Object
Returns the value of attribute photos.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def photos
@photos
end
|
#similar_photos ⇒ Object
Returns the value of attribute similar_photos.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def similar_photos
@similar_photos
end
|
#videos ⇒ Object
Returns the value of attribute videos.
87
88
89
|
# File 'lib/mls/models/listing.rb', line 87
def videos
@videos
end
|
Class Method Details
.all(options = {}) ⇒ Object
currently supported options are filters, page, per_page, offset, order
.amenities ⇒ Object
338
339
340
|
# File 'lib/mls/models/listing.rb', line 338
def amenities
@amenities ||= Yajl::Parser.new.parse(MLS.get('/listings/amenities').body).map(&:to_sym)
end
|
.calculate(filters = {}, operation = nil, column = nil, group = nil) ⇒ Object
333
334
335
336
|
# File 'lib/mls/models/listing.rb', line 333
def calculate(filters = {}, operation = nil, column = nil, group = nil)
response = MLS.get("/listings/calculate", :filters => filters, :operation => operation, :column => column, :group => group)
MLS::Parser.(response.body)[:listings]
end
|
.find(id) ⇒ Object
317
318
319
320
|
# File 'lib/mls/models/listing.rb', line 317
def find(id)
response = MLS.get("/listings/#{id}")
MLS::Listing::Parser.parse(response.body)
end
|
.import(attrs) ⇒ Object
328
329
330
331
|
# File 'lib/mls/models/listing.rb', line 328
def import(attrs)
model = self.new(attrs)
{:status => model.import, :model => model}
end
|
Instance Method Details
105
106
107
|
# File 'lib/mls/models/listing.rb', line 105
def active?
lease_state == 'listed' && workflow_state == 'visible'
end
|
#avatar(size = '150x100#', protocol = 'http') ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/mls/models/listing.rb', line 89
def avatar(size='150x100#', protocol='http')
if avatar_digest
"#{protocol}://#{MLS.image_host}/#{avatar_digest}.jpg?s=#{URI.escape(size)}"
else
address.avatar(size, protocol)
end
end
|
121
122
123
|
# File 'lib/mls/models/listing.rb', line 121
def coworking?
type == 'coworking_space'
end
|
#import ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/mls/models/listing.rb', line 291
def import result = :failure
MLS.post('/import', {:listing => to_hash}, 400) do |response, code|
case code
when 200
result = :duplicate
when 201
result = :created
when 202
result = :updated
when 400
result = :failure
else
raise MLS::Exception::UnexpectedResponse, code
end
MLS::Listing::Parser.update(self, response.body)
end
result
end
|
109
110
111
|
# File 'lib/mls/models/listing.rb', line 109
def inactive?
!self.active?
end
|
113
114
115
|
# File 'lib/mls/models/listing.rb', line 113
def lease?
type == 'lease'
end
|
101
102
103
|
# File 'lib/mls/models/listing.rb', line 101
def leased?
lease_state == 'leased'
end
|
#processing? ⇒ Boolean
97
98
99
|
# File 'lib/mls/models/listing.rb', line 97
def processing?
workflow_state == 'processing'
end
|
#rate(units = '/sqft/mo') ⇒ Object
TODO: remove /desk/mo conversions
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/mls/models/listing.rb', line 152
def rate(units='/sqft/mo')
if rate_units == '/sqft/mo'
if units == '/sqft/mo'
@rate
elsif units == '/sqft/yr'
@rate * 12.0
elsif units == '/mo'
@rate * @size
elsif units == '/yr'
@rate * @size * 12.0
elsif units == '/desk/mo'
@rate * 200.0
else
raise "Invalid rate conversion (#{rate_units} => #{units})"
end
elsif rate_units == '/sqft/yr'
if units == '/sqft/mo'
@rate / 12.0
elsif units == '/sqft/yr'
@rate
elsif units == '/mo'
(@rate / 12.0) * @size
elsif units == '/yr'
@rate * @size
elsif units == '/desk/mo'
(@rate / 12.0) * 200.0
else
raise "Invalid rate conversion (#{rate_units} => #{units})"
end
elsif rate_units == '/mo'
if units == '/sqft/mo'
@rate / @size.to_f
elsif units == '/sqft/yr'
(@rate * 12) / @size.to_f
elsif units == '/mo'
@rate
elsif units == '/yr'
@rate * 12
elsif units == '/desk/mo'
(@rate / @size.to_f) * 200.0
else
raise "Invalid rate conversion (#{rate_units} => #{units})"
end
elsif rate_units == '/yr'
if units == '/sqft/mo'
(@rate / 12.0) / @size.to_f
elsif units == '/sqft/yr'
@rate / @size.to_f
elsif units == '/mo'
@rate / 12.0
elsif units == '/yr'
@rate
elsif units == '/desk/mo'
((@rate / 12.0) / @size.to_f) * 200.0
else
raise "Invalid rate conversion (#{rate_units} => #{units})"
end
elsif rate_units == '/desk/mo'
if units == '/sqft/mo'
@rate / 200.0
elsif units == '/sqft/yr'
((@rate / 200.0) * 12) / @size.to_f
elsif units == '/mo'
@rate
elsif units == '/yr'
@rate * 12
elsif units == '/desk/mo'
@rate
else
raise "Invalid rate conversion (#{rate_units} => #{units})"
end
end
end
|
#request_tour(account, tour = {}) ⇒ Object
Creates a tour request for the listing.
- Paramaters
Examples:
#!ruby
listing = MLS::Listing.find(@id)
info => {:company => 'name', :population => 10, :funding => 'string', :move_id => '2012-09-12'}
listing.request_tour('name', '[email protected]', info) # => #<MLS::Tour>
listing.request_tour('', 'emai', info) # => #<MLS::Tour> will have errors on account
254
255
256
|
# File 'lib/mls/models/listing.rb', line 254
def request_tour(account, tour={})
MLS::Tour.create(id, account, tour)
end
|
#save ⇒ Object
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/mls/models/listing.rb', line 266
def save
return create unless id
MLS.put("/listings/#{id}", {:listing => to_hash}, 400) do |response, code|
if code == 200 || code == 400
MLS::Listing::Parser.update(self, response.body)
code == 200
else
raise MLS::Exception::UnexpectedResponse, code
end
end
end
|
#similar ⇒ Object
311
312
313
|
# File 'lib/mls/models/listing.rb', line 311
def similar
[] end
|
#space_name ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/mls/models/listing.rb', line 126
def space_name
return name if !name.nil?
case space_type
when 'unit'
if unit
"Unit #{unit}"
elsif floor
"#{floor.ordinalize} Floor"
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
|
117
118
119
|
# File 'lib/mls/models/listing.rb', line 117
def sublease?
type == 'sublease'
end
|
#to_hash ⇒ Object
278
279
280
281
282
283
284
285
|
# File 'lib/mls/models/listing.rb', line 278
def to_hash
hash = super
hash[:address_attributes] = address.to_hash if address
hash[:agents_attributes] = agents.inject([]) { |acc, x| acc << x.to_hash; acc } if agents
hash[:photo_ids] = photos.map(&:id) if photos
hash[:videos_attributes] = videos.map(&:to_hash) unless videos.blank?
hash
end
|
#to_param ⇒ Object
287
288
289
|
# File 'lib/mls/models/listing.rb', line 287
def to_param
"#{address.to_param}/#{id}"
end
|