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.



248
249
250
251
252
253
254
255
# File 'lib/dentaku/ast/arithmetic.rb', line 248

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



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

def self.arity
  1
end

.precedenceObject



273
274
275
# File 'lib/dentaku/ast/arithmetic.rb', line 273

def self.precedence
  30
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



257
258
259
# File 'lib/dentaku/ast/arithmetic.rb', line 257

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

#operatorObject



265
266
267
# File 'lib/dentaku/ast/arithmetic.rb', line 265

def operator
  :%
end

#operator_spacingObject



269
270
271
# File 'lib/dentaku/ast/arithmetic.rb', line 269

def operator_spacing
  ""
end

#value(context = {}) ⇒ Object



261
262
263
# File 'lib/dentaku/ast/arithmetic.rb', line 261

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