Class: Lite::Address::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lite/address/parser.rb

Constant Summary collapse

LOOKUPS =
%i[any formal informal intersectional].freeze
CAPITALIZATION_PARTS =
%w[street street_type street2 street_type2 city unit_prefix].freeze
STREET_POSITIONS =
["", "1", "2"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, country_code: "US") ⇒ Parser

Returns a new instance of Parser.



15
16
17
18
# File 'lib/lite/address/parser.rb', line 15

def initialize(address, country_code: "US")
  @address = sanitize_address(address)
  @country_code = sanitize_country_code(country_code)
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



13
14
15
# File 'lib/lite/address/parser.rb', line 13

def address
  @address
end

#country_codeObject (readonly)

Returns the value of attribute country_code.



13
14
15
# File 'lib/lite/address/parser.rb', line 13

def country_code
  @country_code
end

Instance Method Details

#any(args = {}) ⇒ Object



31
32
33
34
35
# File 'lib/lite/address/parser.rb', line 31

def any(args = {})
  return intersectional(args) if regexp.corner.match(address)

  formal(args) || informal(args)
end

#formal(args = {}) ⇒ Object



37
38
39
40
41
42
# File 'lib/lite/address/parser.rb', line 37

def formal(args = {})
  return unless (match = regexp.formal_address.match(address))

  map = match_map(match)
  generate_address(map, args)
end

#informal(args = {}) ⇒ Object



44
45
46
47
48
49
# File 'lib/lite/address/parser.rb', line 44

def informal(args = {})
  return unless (match = regexp.informal_address.match(address))

  map = match_map(match)
  generate_address(map, args)
end

#intersectional(args = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/lite/address/parser.rb', line 51

def intersectional(args = {})
  return unless (match = regexp.intersectional_address.match(address))

  map = match_map(match)
  intersectional_submatch(match, map, "street")
  intersectional_submatch(match, map, "street_type")
  intersectional_rematch(match, map, "street_type")

  generate_address(map, args)
end