Class: AtlasEngine::AddressValidation::Token::Comparison

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_distanceObject (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

#leftObject (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

#qualifierObject (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

#rightObject (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

Returns:

  • (Boolean)


52
53
54
# File 'app/models/atlas_engine/address_validation/token/comparison.rb', line 52

def equal?
  qualifier == :equal
end

#inspectObject



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

Returns:

  • (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