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: "", street_name: "", street_number: "", address2: "", line2: "", neighborhood: "", city: "", province_code: "", zip: "", country_code: "", phone: "") ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/lib/atlas_engine/validation_transcriber/formatter.rb', line 37

def build_address(address1: "", street_name: "", street_number: "", address2: "", line2: "", neighborhood: "",
  city: "", province_code: "", zip: "", country_code: "", phone: "")
  AddressValidation::Address.new(
    address1: address1,
    street_name: street_name,
    street_number: street_number,
    address2: address2,
    line2: line2,
    neighborhood: neighborhood,
    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