Class: DrgDSL::Ast::Comparison

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/drgdsl/ast.rb

Overview

A comparison is either from a table_condition, a condition or a date_expression

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#==, #accept, included, #mdc_equality?, node_classes, #pretty_print, #sep_equality?, type, #type

Constructor Details

#initialize(op:, value:, table_condition: nil) ⇒ Comparison

Returns a new instance of Comparison.



246
247
248
249
250
# File 'lib/drgdsl/ast.rb', line 246

def initialize(op:, value:, table_condition: nil)
  @op = op.to_s.strip
  @value = value
  @table_condition = table_condition
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



244
245
246
# File 'lib/drgdsl/ast.rb', line 244

def op
  @op
end

#table_conditionObject (readonly)

Returns the value of attribute table_condition.



244
245
246
# File 'lib/drgdsl/ast.rb', line 244

def table_condition
  @table_condition
end

#valueObject (readonly)

Returns the value of attribute value.



244
245
246
# File 'lib/drgdsl/ast.rb', line 244

def value
  @value
end

Instance Method Details

#hashObject



262
263
264
# File 'lib/drgdsl/ast.rb', line 262

def hash
  @hash ||= [type, op, value, table_condition].hash
end

#to_hashObject



252
253
254
255
256
257
258
259
260
# File 'lib/drgdsl/ast.rb', line 252

def to_hash
  {
    comparison: {
      op: op,
      value: value.to_hash,
      table_condition: table_condition&.to_hash
    }
  }
end