Class: JSONP3::Path::LogicalNotExpression

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



144
145
146
147
# File 'lib/json_p3/path/filter.rb', line 144

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

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



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

def expression
  @expression
end

Instance Method Details

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



157
158
159
160
161
# File 'lib/json_p3/path/filter.rb', line 157

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

#evaluate(context) ⇒ Object



149
150
151
# File 'lib/json_p3/path/filter.rb', line 149

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

#hashObject



165
166
167
# File 'lib/json_p3/path/filter.rb', line 165

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

#to_sObject



153
154
155
# File 'lib/json_p3/path/filter.rb', line 153

def to_s
  "!#{@expression}"
end