Class: JSONP3::Path::FilterExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/json_p3/path/filter.rb

Overview

An expression that evaluates to true or false.

Defined Under Namespace

Classes: Precedence

Instance Attribute Summary collapse

Attributes inherited from Expression

#token

Instance Method Summary collapse

Constructor Details

#initialize(token, expression) ⇒ FilterExpression

Returns a new instance of FilterExpression.



28
29
30
31
# File 'lib/json_p3/path/filter.rb', line 28

def initialize(token, expression)
  super(token)
  @expression = expression
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



26
27
28
# File 'lib/json_p3/path/filter.rb', line 26

def expression
  @expression
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



41
42
43
44
45
# File 'lib/json_p3/path/filter.rb', line 41

def ==(other)
  self.class == other.class &&
    @expression == other.expression &&
    @token == other.token
end

#evaluate(context) ⇒ Object



33
34
35
# File 'lib/json_p3/path/filter.rb', line 33

def evaluate(context)
  JSONP3::Path.truthy?(@expression.evaluate(context))
end

#hashObject



49
50
51
# File 'lib/json_p3/path/filter.rb', line 49

def hash
  [@expression, @token].hash
end

#to_sObject



37
38
39
# File 'lib/json_p3/path/filter.rb', line 37

def to_s
  to_canonical_string(@expression, Precedence::LOWEST)
end