Class: DrgDSL::Ast::TableCondition

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

Overview

There are 3 variants of table conditions (in_table, in_tables, all_in_table)

A table condition can have an optional comparison. Tables refers to the table names (the internal names)

Constant Summary collapse

IN_TABLE =
'in table'
IN_TABLES =
'in tables'
ALL_IN_TABLE =
'all in table'

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:, tables:, comparison: nil) ⇒ TableCondition

Returns a new instance of TableCondition.

Parameters:

  • op (String)

    IN_TABLE, IN_TABLES or ALL_IN_TABLE

  • tables (Array<String>)

    one or more table names



323
324
325
326
327
# File 'lib/drgdsl/ast.rb', line 323

def initialize(op:, tables:, comparison: nil)
  @op = op
  @tables = Array(tables).map(&:to_s)
  @comparison = comparison
end

Instance Attribute Details

#comparisonObject (readonly)

Returns the value of attribute comparison.



319
320
321
# File 'lib/drgdsl/ast.rb', line 319

def comparison
  @comparison
end

#opObject (readonly)

Returns the value of attribute op.



319
320
321
# File 'lib/drgdsl/ast.rb', line 319

def op
  @op
end

#tablesObject (readonly)

Returns the value of attribute tables.



319
320
321
# File 'lib/drgdsl/ast.rb', line 319

def tables
  @tables
end

Instance Method Details

#hashObject



339
340
341
# File 'lib/drgdsl/ast.rb', line 339

def hash
  @hash ||= [type, op, *tables, comparison].hash
end

#to_hashObject



329
330
331
332
333
334
335
336
337
# File 'lib/drgdsl/ast.rb', line 329

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