Class: AtlasEngine::AddressValidation::Token::Comparison
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Token::Comparison
- Extended by:
- T::Sig
- Includes:
- Comparable
- Defined in:
- app/models/atlas_engine/address_validation/token/comparison.rb
Constant Summary collapse
- QUALIFIERS =
T.let( [:equal, :prefix, :suffix, :comp].freeze, T::Array[Symbol], )
Instance Attribute Summary collapse
-
#edit_distance ⇒ Object
readonly
Returns the value of attribute edit_distance.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #equal? ⇒ Boolean
-
#initialize(left:, right:, qualifier:, edit_distance:) ⇒ Comparison
constructor
A new instance of Comparison.
- #inspect ⇒ Object
- #preceeds?(other) ⇒ Boolean
Constructor Details
#initialize(left:, right:, qualifier:, edit_distance:) ⇒ Comparison
Returns a new instance of Comparison.
33 34 35 36 37 38 39 40 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 33 def initialize(left:, right:, qualifier:, edit_distance:) raise "Unknown qualifier" unless qualifier.in?(QUALIFIERS) @left = left @right = right @qualifier = qualifier @edit_distance = edit_distance end |
Instance Attribute Details
#edit_distance ⇒ Object (readonly)
Returns the value of attribute edit_distance.
23 24 25 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 23 def edit_distance @edit_distance end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
17 18 19 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 17 def left @left end |
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
20 21 22 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 20 def qualifier @qualifier end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
17 18 19 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 17 def right @right end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 43 def <=>(other) if edit_distance == other.edit_distance qualifier_rank <=> other.qualifier_rank else edit_distance <=> other.edit_distance end end |
#equal? ⇒ Boolean
52 53 54 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 52 def equal? qualifier == :equal end |
#inspect ⇒ Object
62 63 64 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 62 def inspect "<comp left:#{left.inspect} #{qualifier.to_s.upcase} right:#{right.inspect} edit:#{edit_distance}/>" end |
#preceeds?(other) ⇒ Boolean
57 58 59 |
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 57 def preceeds?(other) left.preceeds?(other.left) && right.preceeds?(other.right) end |