Class: AtlasEngine::AddressValidation::Es::Validators::RestrictionEvaluator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/models/atlas_engine/address_validation/es/validators/restriction_evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ RestrictionEvaluator

Returns a new instance of RestrictionEvaluator.



13
14
15
# File 'app/models/atlas_engine/address_validation/es/validators/restriction_evaluator.rb', line 13

def initialize(address)
  @address = address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



10
11
12
# File 'app/models/atlas_engine/address_validation/es/validators/restriction_evaluator.rb', line 10

def address
  @address
end

Instance Method Details

#supported_address?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/atlas_engine/address_validation/es/validators/restriction_evaluator.rb', line 18

def supported_address?
  country_profile = CountryProfile.for(T.must(address.country_code))

  country_profile.attributes.dig("validation", "restrictions").map do |restriction|
    class_name = restriction["class"]
    additional_params = restriction["params"]&.transform_keys(&:to_sym)

    params = { address: address }
    params = params.merge!({ params: additional_params }) if additional_params.present?

    return false if class_name.constantize.send(:apply?, **params)
  end

  true
end