Class: AtlasEngine::ValidationTranscriber::EnglishStreetParser
- Inherits:
-
Object
- Object
- AtlasEngine::ValidationTranscriber::EnglishStreetParser
- Includes:
- AddressParsingHelper
- Defined in:
- app/lib/atlas_engine/validation_transcriber/english_street_parser.rb
Instance Method Summary collapse
-
#initialize ⇒ EnglishStreetParser
constructor
A new instance of EnglishStreetParser.
- #parse(street:) ⇒ Object
Methods included from AddressParsingHelper
#address_constants, #directional?, #street_suffix?
Constructor Details
#initialize ⇒ EnglishStreetParser
Returns a new instance of EnglishStreetParser.
9 10 11 |
# File 'app/lib/atlas_engine/validation_transcriber/english_street_parser.rb', line 9 def initialize super end |
Instance Method Details
#parse(street:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 'app/lib/atlas_engine/validation_transcriber/english_street_parser.rb', line 13 def parse(street:) return {} if street.blank? # Expected format: [pre_directional, name, suffix, post_directional] # Note that pre_directional and post_directional may be absent, one word ("East"), or two words ("North East") pre_directional = nil suffix = nil post_directional = nil tokens = street.split(" ") if directional?(tokens[0]) if directional?(tokens[1]) pre_directional = tokens[0..1].join(" ") tokens = tokens[2..-1] else pre_directional = tokens[0] tokens = tokens[1..-1] end end if directional?(tokens[-1]) if directional?(tokens[-2]) post_directional = tokens[-2..-1].join(" ") tokens = tokens[0..-3] else post_directional = tokens[-1] tokens = tokens[0..-2] end end if street_suffix?(tokens[-1]) suffix = tokens[-1] tokens = tokens[0..-2] end { pre_directional: pre_directional, name: tokens.join(" "), suffix: suffix, post_directional: post_directional, }.compact_blank.to_h end |