Class: Search

Inherits:
MLS::Model show all
Defined in:
lib/mls/models/search.rb

Constant Summary collapse

STATUS_OPTIONS =
%w(active hold cold closed)
STAGE_OPTIONS =
%w(initiated contacted delivered connected toured loi signed coworking)
BUDGET_UNITS =
%w(per_month per_year per_sqft_per_year)
TERMS =
%w(<1 1-2 3-5 5+ flexible)
MOVE_INS =
%w(<3 3-6 6-12 12+ flexible)

Instance Method Summary collapse

Instance Method Details

#filterObject



31
32
33
# File 'lib/mls/models/search.rb', line 31

def filter
  JSON.parse (read_attribute(:filter) || {}).to_json, object_class: OpenStruct
end

#move_in_units(value = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mls/models/search.rb', line 39

def move_in_units(value=nil)
  value ||= self.move_in
  case value
  when "<1"
    "month"
  when "flexible"
    ""
  else
    "months"
  end
end

#nameObject



20
21
22
# File 'lib/mls/models/search.rb', line 20

def name
  read_attribute(:name) || &.company || &.name
end

#regionsObject



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

def regions
  Region.where(id: self.region_ids)
end

#term_units(value = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mls/models/search.rb', line 51

def term_units(value=nil)
  value ||= self.term
  case value
  when "<1"
    "year"
  when "flexible"
    ""
  else
    "years"
  end
end

#to_json(options = {}) ⇒ Object



24
25
26
27
28
29
# File 'lib/mls/models/search.rb', line 24

def to_json(options={})
  output = super(options)
  output = JSON.parse(super)
  output["filter"] = read_attribute(:filter)
  output.to_json
end