Class: AtlasEngine::ValidationTranscriber::FrenchStreetParser
- Inherits:
-
Object
- Object
- AtlasEngine::ValidationTranscriber::FrenchStreetParser
- Includes:
- AddressParsingHelper
- Defined in:
- app/lib/atlas_engine/validation_transcriber/french_street_parser.rb
Instance Method Summary collapse
-
#initialize ⇒ FrenchStreetParser
constructor
A new instance of FrenchStreetParser.
- #parse(street:) ⇒ Object
Methods included from AddressParsingHelper
#address_constants, #directional?, #street_suffix?
Constructor Details
#initialize ⇒ FrenchStreetParser
Returns a new instance of FrenchStreetParser.
9 10 11 |
# File 'app/lib/atlas_engine/validation_transcriber/french_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 |
# File 'app/lib/atlas_engine/validation_transcriber/french_street_parser.rb', line 13 def parse(street:) return {} if street.blank? # Expected format: [suffix, pre_directional, name, post_directional] # Note that the directionals may be absent. # Suffix is actually a prefix in French, but we keep the existing terminology for cross-language consistency. suffix = nil pre_directional = nil post_directional = nil tokens = street.split(" ") if street_suffix?(tokens[0]) suffix = tokens[0] tokens = tokens[1..-1] end if directional?(tokens[0]) pre_directional = tokens[0] tokens = tokens[1..-1] end if directional?(tokens[-1]) post_directional = 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 |