Class: KQL::Matcher::Comparison

Inherits:
KQL::Matcher show all
Defined in:
lib/kql/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accessor, operator, value) ⇒ Comparison

Returns a new instance of Comparison.



65
66
67
68
69
# File 'lib/kql/matcher.rb', line 65

def initialize(accessor, operator, value)
  @accessor = accessor
  @operator = operator
  @value = value
end

Instance Attribute Details

#accessorObject (readonly)

Returns the value of attribute accessor.



63
64
65
# File 'lib/kql/matcher.rb', line 63

def accessor
  @accessor
end

#operatorObject (readonly)

Returns the value of attribute operator.



63
64
65
# File 'lib/kql/matcher.rb', line 63

def operator
  @operator
end

#valueObject (readonly)

Returns the value of attribute value.



63
64
65
# File 'lib/kql/matcher.rb', line 63

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/kql/matcher.rb', line 77

def ==(other)
  return false unless other.is_a?(Comparison)

  other.accessor == accessor &&
    other.operator == operator &&
    other.value == value
end

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/kql/matcher.rb', line 71

def match?(node)
  return false unless accessor.match?(node)

  operator.execute(value.coerce(accessor.execute(node)), value.value)
end