Sha256: 6aad0cd5cb8e654292dbfb57014b06c4267120f9c1146bcd6e704b4f99cfc3da

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

class Search < MLS::Model

  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)
  
  belongs_to :account
  belongs_to :broker, class_name: "Account"
  belongs_to :manager, class_name: "Account"
  belongs_to :lead
  
  has_many :suggestions
  has_many :email_digests
  has_many :tasks, :as => :subject
  
  accepts_nested_attributes_for :account
  
  def name
    read_attribute(:name) || account&.company || account&.name
  end
  
  def to_json(options={})
    output = super(options)
    output = JSON.parse(super)
    output["filter"] = read_attribute(:filter)
    output.to_json
  end
  
  def filter
    JSON.parse (read_attribute(:filter) || {}).to_json, object_class: OpenStruct
  end
  
  def regions
    Region.where(id: self.region_ids)
  end
  
  def move_in_units(value=nil)
    value ||= self.move_in
    case value
    when "<1"
      "month"
    when "flexible"
      ""
    else
      "months"
    end
  end
  
  def term_units(value=nil)
    value ||= self.term
    case value
    when "<1"
      "year"
    when "flexible"
      ""
    else
      "years"
    end
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mls-1.9.0 lib/mls/models/search.rb
mls-1.8.0 lib/mls/models/search.rb
mls-1.7.0 lib/mls/models/search.rb
mls-1.6.0 lib/mls/models/search.rb