Class: Dentaku::AST::Subtraction

Inherits:
Arithmetic show all
Defined in:
lib/dentaku/ast/arithmetic.rb

Constant Summary

Constants inherited from Arithmetic

Arithmetic::DECIMAL, Arithmetic::INTEGER

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Arithmetic

#initialize, #type

Methods inherited from Operation

#accept, #dependencies, #display_operator, #initialize, max_param_count, min_param_count, right_associative?

Methods inherited from Node

arity, #dependencies, #name, peek, #type

Constructor Details

This class inherits a constructor from Dentaku::AST::Arithmetic

Class Method Details

.precedenceObject



135
136
137
# File 'lib/dentaku/ast/arithmetic.rb', line 135

def self.precedence
  10
end

Instance Method Details

#operatorObject



131
132
133
# File 'lib/dentaku/ast/arithmetic.rb', line 131

def operator
  :-
end

#value(context = {}) ⇒ Object



139
140
141
142
143
144
145
146
147
148
# File 'lib/dentaku/ast/arithmetic.rb', line 139

def value(context = {})
  left_value = left.value(context)
  right_value = right.value(context)

  if left.type == :datetime || datetime?(left_value)
    Dentaku::DateArithmetic.new(left_value).sub(right_value)
  else
    calculate(left_value, right_value)
  end
end