Class: AtlasEngine::FieldDecompounder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/models/atlas_engine/field_decompounder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field:, value:, country_profile:) ⇒ FieldDecompounder

Returns a new instance of FieldDecompounder.



11
12
13
14
15
# File 'app/models/atlas_engine/field_decompounder.rb', line 11

def initialize(field:, value:, country_profile:)
  @field = field
  @value = value
  @country_profile = country_profile
end

Instance Attribute Details

#country_profileObject (readonly)

Returns the value of attribute country_profile.



8
9
10
# File 'app/models/atlas_engine/field_decompounder.rb', line 8

def country_profile
  @country_profile
end

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'app/models/atlas_engine/field_decompounder.rb', line 8

def field
  @field
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'app/models/atlas_engine/field_decompounder.rb', line 8

def value
  @value
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
# File 'app/models/atlas_engine/field_decompounder.rb', line 18

def call
  country_profile.decompounding_patterns(field)&.each do |pattern|
    transliterated_street = ActiveSupport::Inflector.transliterate(value.to_s)
    if (match = transliterated_street.match(expanded_pattern(pattern)))
      return (match[:pre] + match[:name] + " " + match[:suffix] + match[:post]).strip
    end
  end

  value
end