Class: AtlasEngine::AddressValidation::Token::Sequence::Comparator
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Token::Sequence::Comparator
- Extended by:
- T::Sig
- Defined in:
- app/models/atlas_engine/address_validation/token/sequence/comparator.rb
Constant Summary collapse
- MAX_ALLOWED_EDIT_DISTANCE_PERCENT =
0.5
Instance Attribute Summary collapse
-
#comparison_cache ⇒ Object
readonly
Returns the value of attribute comparison_cache.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize(left_sequence:, right_sequence:, comparison_policy: ComparisonPolicy::DEFAULT_POLICY) ⇒ Comparator
constructor
A new instance of Comparator.
Constructor Details
#initialize(left_sequence:, right_sequence:, comparison_policy: ComparisonPolicy::DEFAULT_POLICY) ⇒ Comparator
Returns a new instance of Comparator.
26 27 28 29 30 31 32 33 |
# File 'app/models/atlas_engine/address_validation/token/sequence/comparator.rb', line 26 def initialize(left_sequence:, right_sequence:, comparison_policy: ComparisonPolicy::DEFAULT_POLICY) @left = left_sequence @right = right_sequence @comparison_policy = comparison_policy @comparison_cache = Hash.new do |h, (l_tok, r_tok)| h[[l_tok, r_tok]] = AddressValidation::Token::Comparator.new(l_tok, r_tok).compare end end |
Instance Attribute Details
#comparison_cache ⇒ Object (readonly)
Returns the value of attribute comparison_cache.
15 16 17 |
# File 'app/models/atlas_engine/address_validation/token/sequence/comparator.rb', line 15 def comparison_cache @comparison_cache end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
12 13 14 |
# File 'app/models/atlas_engine/address_validation/token/sequence/comparator.rb', line 12 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
12 13 14 |
# File 'app/models/atlas_engine/address_validation/token/sequence/comparator.rb', line 12 def right @right end |
Instance Method Details
#compare ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/atlas_engine/address_validation/token/sequence/comparator.rb', line 36 def compare result = left.permutations.product(right.permutations).map do |left_permutation, right_permutation| flattened_sequence_compare(left_permutation, right_permutation) end T.must(result.min) end |