Class: AtlasEngine::AddressImporter::Validation::Wrapper

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
ImportLogHelper, Validator
Defined in:
app/models/atlas_engine/address_importer/validation/wrapper.rb

Defined Under Namespace

Classes: AddressStruct

Constant Summary

Constants included from ImportLogHelper

ImportLogHelper::TEST_TIMESTAMP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImportLogHelper

#import_log_error, #import_log_info

Methods included from LogHelper

#log_error, #log_info, #log_warn

Constructor Details

#initialize(country_import:, validator: nil, log_invalid_records: true) ⇒ Wrapper

Returns a new instance of Wrapper.



24
25
26
27
28
# File 'app/models/atlas_engine/address_importer/validation/wrapper.rb', line 24

def initialize(country_import:, validator: nil, log_invalid_records: true)
  @country_import = country_import
  @validator = validator || DefaultValidator.new(country_code: country_import.country_code)
  @log_invalid_records = log_invalid_records
end

Instance Attribute Details

#country_importObject (readonly)

Returns the value of attribute country_import.



13
14
15
# File 'app/models/atlas_engine/address_importer/validation/wrapper.rb', line 13

def country_import
  @country_import
end

#validatorObject (readonly)

Returns the value of attribute validator.



13
14
15
# File 'app/models/atlas_engine/address_importer/validation/wrapper.rb', line 13

def validator
  @validator
end

Instance Method Details

#valid?(address) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'app/models/atlas_engine/address_importer/validation/wrapper.rb', line 31

def valid?(address)
  return false unless address

  errors = validation_errors(address)

  return true if errors.empty?

  log_invalid_address(address, errors) if @log_invalid_records
  false
end