Class: Inquiry

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

Constant Summary collapse

TERMS =
%w(<1 1-2 3-5 5+ flexible)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_day(filter) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/mls/models/inquiry.rb', line 58

def self.by_day(filter)
  req = Net::HTTP::Get.new("/inquiries/by_day")
  req.body = {
    where: filter
  }.to_json
  connection.instance_variable_get(:@connection).send_request(req).body
end

.by_week(filter) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/mls/models/inquiry.rb', line 66

def self.by_week(filter)
  req = Net::HTTP::Get.new("/inquiries/by_week")
  req.body = {
    where: filter
  }.to_json
  connection.instance_variable_get(:@connection).send_request(req).body
end

Instance Method Details

#account_attributes=(account_attrs) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mls/models/inquiry.rb', line 29

def ()
   = &.with_indifferent_access
  self. = if .nil?
    nil
  elsif ["id"]
    accnt = Account.find(.delete("id"))
    accnt.assign_attributes()
    accnt
  else
    if ["email_addresses_attributes"]
      email_address = EmailAddress.filter(address: ["email_addresses_attributes"].map{|ea| ea["address"].downcase}, account_id: true).first
      accnt = email_address.
      accnt.assign_attributes()
    end
    
    if !accnt && ["phones_attributes"]
      phone = Phone.filter(number: ["phones_attributes"].map{|p| PhoneValidator.normalize(p["number"])}, account_id: true).first
      accnt = phone.
      accnt.assign_attributes()
    end
    
    if !accnt
      accnt = Account.new()
    end

    accnt
  end
end

#propertyObject



11
12
13
# File 'lib/mls/models/inquiry.rb', line 11

def property
  subject.is_a? MLS::Model::Listing ? subject.property : subject
end

#term_units(value = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mls/models/inquiry.rb', line 15

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