Class: AtlasEngine::AddressValidation::Validators::FullAddress::AddressComparison
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Validators::FullAddress::AddressComparison
- Extended by:
- T::Sig
- Includes:
- Comparable
- Defined in:
- app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#candidate ⇒ Object
readonly
Returns the value of attribute candidate.
-
#datastore ⇒ Object
readonly
Returns the value of attribute datastore.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #building_comparison ⇒ Object
- #city_comparison ⇒ Object
- #components ⇒ Object
- #for(component) ⇒ Object
-
#initialize(address:, candidate:, datastore:) ⇒ AddressComparison
constructor
A new instance of AddressComparison.
- #inspect ⇒ Object
- #potential_match? ⇒ Boolean
- #province_code_comparison ⇒ Object
- #relevant_components ⇒ Object
- #street_comparison ⇒ Object
- #zip_comparison ⇒ Object
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
#address ⇒ Object (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 |
#candidate ⇒ Object (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 |
#datastore ⇒ Object (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_comparison ⇒ Object
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_comparison ⇒ Object
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 |
#components ⇒ Object
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 |
#inspect ⇒ Object
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
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_comparison ⇒ Object
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_components ⇒ Object
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_comparison ⇒ Object
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_comparison ⇒ Object
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 |