Class: JSONP3::FilterExpression

Inherits:
Expression show all
Defined in:
lib/json_p3/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.



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

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

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



24
25
26
# File 'lib/json_p3/filter.rb', line 24

def expression
  @expression
end

Instance Method Details

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



39
40
41
42
43
# File 'lib/json_p3/filter.rb', line 39

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

#evaluate(context) ⇒ Object



31
32
33
# File 'lib/json_p3/filter.rb', line 31

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

#hashObject



47
48
49
# File 'lib/json_p3/filter.rb', line 47

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

#to_sObject



35
36
37
# File 'lib/json_p3/filter.rb', line 35

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