Class: Rgviz::ScalarFunctionColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/rgviz/nodes.rb

Constant Summary collapse

Concat =
Token::Concat
DateDiff =
Token::DateDiff
Day =
Token::Day
DayOfWeek =
Token::DayOfWeek
Difference =
Token::MINUS
Hour =
Token::Hour
Lower =
Token::Lower
Millisecond =
Token::Millisecond
Minute =
Token::Minute
Month =
Token::Month
Now =
Token::Now
Product =
Token::STAR
Quarter =
Token::Quarter
Quotient =
Token::SLASH
Round =
Token::Round
Floor =
Token::Floor
Second =
Token::Second
Sum =
Token::PLUS
ToDate =
Token::ToDate
Upper =
Token::Upper
Year =
Token::Year

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function, *arguments) ⇒ ScalarFunctionColumn

Returns a new instance of ScalarFunctionColumn.



436
437
438
439
# File 'lib/rgviz/nodes.rb', line 436

def initialize(function, *arguments)
  @function = function
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



434
435
436
# File 'lib/rgviz/nodes.rb', line 434

def arguments
  @arguments
end

#functionObject

Returns the value of attribute function.



433
434
435
# File 'lib/rgviz/nodes.rb', line 433

def function
  @function
end

Instance Method Details

#accept(visitor) ⇒ Object



441
442
443
444
445
446
# File 'lib/rgviz/nodes.rb', line 441

def accept(visitor)
  if visitor.visit_scalar_function_column(self)
    arguments.each{|x| x.accept visitor}
  end
  visitor.end_visit_scalar_function_column self
end

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

Returns:

  • (Boolean)


458
459
460
# File 'lib/rgviz/nodes.rb', line 458

def eql?(other)
  other.class == ScalarFunctionColumn && other.function == @function && other.arguments == @arguments
end

#hashObject



448
449
450
451
452
453
454
455
456
# File 'lib/rgviz/nodes.rb', line 448

def hash
  return @hash if @hash
  @hash = 1
  @hash = @hash * 31 + @function.hash
  @arguments.each do |arg|
    @hash = @hash * 31 + arg.hash
  end
  @hash
end

#to_sObject



464
465
466
467
468
469
470
471
# File 'lib/rgviz/nodes.rb', line 464

def to_s
  case function
  when Sum, Difference, Product, Quotient
    "#{arguments[0].to_s} #{function} #{arguments[1].to_s}"
  else
    "#{function}(#{arguments.map(&:to_s).join(', ')})"
  end
end