Class: AtlasEngine::AddressValidation::Validators::FullAddress::AddressComparison

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address:, candidate:, datastore:) ⇒ AddressComparison

Returns a new instance of AddressComparison.



17
18
19
20
21
22
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 17

def initialize(address:, candidate:, datastore:)
  @address = address
  @candidate = candidate
  @datastore = datastore
  @comparators_hash = {}
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



12
13
14
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 12

def address
  @address
end

#candidateObject (readonly)

Returns the value of attribute candidate.



12
13
14
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 12

def candidate
  @candidate
end

#datastoreObject (readonly)

Returns the value of attribute datastore.



12
13
14
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 12

def datastore
  @datastore
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 25

def <=>(other)
  # prefer addresses having more matched fields, e.g. matching on street + city + zip is better than
  # just matching on street + zip, or street + province
  matches = comparators.count(&:match?) <=> other.comparators.count(&:match?)
  return matches * -1 if matches.nonzero?

  # merge all sequence comparisons together, erasing the individual field boundaries, and prefer
  # the most favorable aggregate comparison
  merged_comparison <=> other.merged_comparison
end

#building_comparisonObject



67
68
69
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 67

def building_comparison
  T.cast(self.for(:building), BuildingComparison)
end

#city_comparisonObject



57
58
59
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 57

def city_comparison
  T.cast(self.for(:city), CityComparison)
end

#componentsObject



85
86
87
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 85

def components
  comparators.map(&:component)
end

#for(component) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 72

def for(component)
  @comparators_hash[component] ||= begin
    klass = datastore.country_profile.validation.component_comparison(component)
    klass.new(
      address: address,
      candidate: candidate,
      datastore: datastore,
      component: component,
    )
  end
end

#inspectObject



37
38
39
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 37

def inspect
  "<addrcomp street#{comparators.inspect}/>"
end

#potential_match?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 42

def potential_match?
  street_comparison.sequence_comparison.nil? || T.must(street_comparison.sequence_comparison).potential_match?
end

#province_code_comparisonObject



62
63
64
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 62

def province_code_comparison
  T.cast(self.for(:province_code), ProvinceCodeComparison)
end

#relevant_componentsObject



90
91
92
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 90

def relevant_components
  comparators.select(&:relevant?).map(&:component)
end

#street_comparisonObject



52
53
54
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 52

def street_comparison
  T.cast(self.for(:street), StreetComparison)
end

#zip_comparisonObject



47
48
49
# File 'app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb', line 47

def zip_comparison
  T.cast(self.for(:zip), ZipComparison)
end