Class: AtlasEngine::AddressValidation::Token::Comparator
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Token::Comparator
- Extended by:
- T::Sig
- Includes:
- Gem::Text
- Defined in:
- app/models/atlas_engine/address_validation/token/comparator.rb
Instance Attribute Summary collapse
-
#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_token, right_token) ⇒ Comparator
constructor
A new instance of Comparator.
Constructor Details
#initialize(left_token, right_token) ⇒ Comparator
Returns a new instance of Comparator.
17 18 19 20 |
# File 'app/models/atlas_engine/address_validation/token/comparator.rb', line 17 def initialize(left_token, right_token) @left = T.let(left_token, Token) @right = T.let(right_token, Token) end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
14 15 16 |
# File 'app/models/atlas_engine/address_validation/token/comparator.rb', line 14 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
14 15 16 |
# File 'app/models/atlas_engine/address_validation/token/comparator.rb', line 14 def right @right end |
Instance Method Details
#compare ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/atlas_engine/address_validation/token/comparator.rb', line 23 def compare left_value = left.value right_value = right.value if left_value == right_value Comparison.new(left: left, right: right, qualifier: :equal, edit_distance: 0) else edit = levenshtein_distance(left_value, right_value) if right_value.start_with?(left_value) || left_value.start_with?(right_value) Comparison.new(left: left, right: right, qualifier: :prefix, edit_distance: edit) elsif right_value.end_with?(left_value) || left_value.end_with?(right_value) Comparison.new(left: left, right: right, qualifier: :suffix, edit_distance: edit) else Comparison.new(left: left, right: right, qualifier: :comp, edit_distance: edit) end end end |