Class: JSONP3::FilterExpression
- Inherits:
-
Expression
- Object
- Expression
- JSONP3::FilterExpression
- 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
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Attributes inherited from Expression
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #evaluate(context) ⇒ Object
- #hash ⇒ Object
-
#initialize(token, expression) ⇒ FilterExpression
constructor
A new instance of FilterExpression.
- #to_s ⇒ Object
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
#expression ⇒ Object (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 |
#hash ⇒ Object
47 48 49 |
# File 'lib/json_p3/filter.rb', line 47 def hash [@expression, @token].hash end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/json_p3/filter.rb', line 35 def to_s to_canonical_string(@expression, Precedence::LOWEST) end |