Class: Roqua::Healthy::A19::AddressParser

Inherits:
Object
  • Object
show all
Defined in:
lib/roqua/healthy/a19/address_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ AddressParser

Returns a new instance of AddressParser.



8
9
10
# File 'lib/roqua/healthy/a19/address_parser.rb', line 8

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/roqua/healthy/a19/address_parser.rb', line 6

def message
  @message
end

Instance Method Details

#address_typeObject



12
13
14
15
# File 'lib/roqua/healthy/a19/address_parser.rb', line 12

def address_type
  return nil unless record
  record.fetch('PID.11.7')
end

#cityObject



30
31
32
33
# File 'lib/roqua/healthy/a19/address_parser.rb', line 30

def city
  return nil unless record
  record.fetch('PID.11.3')
end

#countryObject



40
41
42
43
# File 'lib/roqua/healthy/a19/address_parser.rb', line 40

def country
  return nil unless record
  record.fetch('PID.11.6')
end

#recordObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/roqua/healthy/a19/address_parser.rb', line 45

def record
  # PID.11.7 address types:
  # M: Mailing
  # P: Permanent
  # H: Home
  # L: Legal address

  @record ||= get_address_of_type(message, 'M') ||
              get_address_of_type(message, 'P') ||
              get_address_of_type(message, 'H') ||
              get_address_of_type(message, 'L')
end

#streetObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roqua/healthy/a19/address_parser.rb', line 17

def street
  return nil if record.blank? || record.fetch('PID.11.1').blank?

  street = record.fetch('PID.11.1').fetch('PID.11.1.1')
  suffix = record.fetch('PID.11.2', nil)

  if suffix.present? && !street.end_with?(suffix)
    street + suffix
  else
    street
  end
end

#zipcodeObject



35
36
37
38
# File 'lib/roqua/healthy/a19/address_parser.rb', line 35

def zipcode
  return nil unless record
  record.fetch('PID.11.5')
end