Module: AtlasEngine::ValidationTranscriber::Formatter

Extended by:
T::Sig
Included in:
Gb::ValidationTranscriber::FullAddressParser, AddressParserBase, AddressParserPreprocessor
Defined in:
app/lib/atlas_engine/validation_transcriber/formatter.rb

Instance Method Summary collapse

Instance Method Details

#build_address(address1: "", address2: "", city: "", province_code: "", zip: "", country_code: "", phone: "") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/lib/atlas_engine/validation_transcriber/formatter.rb', line 33

def build_address(address1: "", address2: "", city: "", province_code: "", zip: "", country_code: "", phone: "")
  AddressValidation::Address.new(
    address1: address1,
    address2: address2,
    city: city,
    province_code: province_code,
    zip: zip,
    country_code: country_code,
    phone: phone,
  )
end

#strip_trailing_punctuation(text) ⇒ Object



10
11
12
# File 'app/lib/atlas_engine/validation_transcriber/formatter.rb', line 10

def strip_trailing_punctuation(text)
  text.presence&.sub(/[\s,\-]+$/, "")
end

#strip_word(haystack, needle) ⇒ Object



15
16
17
18
19
20
# File 'app/lib/atlas_engine/validation_transcriber/formatter.rb', line 15

def strip_word(haystack, needle)
  string = haystack.sub(/([\s]|^)(#{Regexp.escape(needle)})([\s]|$)/i, " ").strip
  string = string.sub(/([\s,]|^)(#{Regexp.escape(needle)})([\s,]|$)/i, "").strip
  string = strip_trailing_punctuation(string)
  string || ""
end