Class: JSONP3::LogicalNotExpression

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

Overview

An expression prefixed with the logical not operator.

Instance Attribute Summary collapse

Attributes inherited from Expression

#token

Instance Method Summary collapse

Constructor Details

#initialize(token, expression) ⇒ LogicalNotExpression

Returns a new instance of LogicalNotExpression.



142
143
144
145
# File 'lib/json_p3/filter.rb', line 142

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

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



140
141
142
# File 'lib/json_p3/filter.rb', line 140

def expression
  @expression
end

Instance Method Details

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



155
156
157
158
159
# File 'lib/json_p3/filter.rb', line 155

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

#evaluate(context) ⇒ Object



147
148
149
# File 'lib/json_p3/filter.rb', line 147

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

#hashObject



163
164
165
# File 'lib/json_p3/filter.rb', line 163

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

#to_sObject



151
152
153
# File 'lib/json_p3/filter.rb', line 151

def to_s
  "!#{@expression}"
end