Class: Dentaku::AST::Percentage

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

#type

Methods inherited from Operation

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

Methods inherited from Node

#name, resolve_class, #type

Constructor Details

#initialize(child) ⇒ Percentage

Returns a new instance of Percentage.



197
198
199
200
201
202
203
204
# File 'lib/dentaku/ast/arithmetic.rb', line 197

def initialize(child)
  @left = child

  unless valid_left?
    raise NodeError.new(:numeric, left.type, :left),
          "#{self.class} requires a numeric operand"
  end
end

Class Method Details

.arityObject



193
194
195
# File 'lib/dentaku/ast/arithmetic.rb', line 193

def self.arity
  1
end

.precedenceObject



222
223
224
# File 'lib/dentaku/ast/arithmetic.rb', line 222

def self.precedence
  30
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



206
207
208
# File 'lib/dentaku/ast/arithmetic.rb', line 206

def dependencies(context = {})
  @left.dependencies(context)
end

#operatorObject



214
215
216
# File 'lib/dentaku/ast/arithmetic.rb', line 214

def operator
  :%
end

#operator_spacingObject



218
219
220
# File 'lib/dentaku/ast/arithmetic.rb', line 218

def operator_spacing
  ""
end

#value(context = {}) ⇒ Object



210
211
212
# File 'lib/dentaku/ast/arithmetic.rb', line 210

def value(context = {})
  cast(left.value(context)) * 0.01
end