Class: Dentaku::AST::Percentage

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

Constant Summary

Constants inherited from Node

Node::STATIC_CONTEXT, Node::STATIC_MODE_KEY

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, #pure?, resolve_class, #type

Constructor Details

#initialize(child) ⇒ Percentage

Returns a new instance of Percentage.



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

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



242
243
244
# File 'lib/dentaku/ast/arithmetic.rb', line 242

def self.arity
  1
end

.precedenceObject



271
272
273
# File 'lib/dentaku/ast/arithmetic.rb', line 271

def self.precedence
  30
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



255
256
257
# File 'lib/dentaku/ast/arithmetic.rb', line 255

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

#operatorObject



263
264
265
# File 'lib/dentaku/ast/arithmetic.rb', line 263

def operator
  :%
end

#operator_spacingObject



267
268
269
# File 'lib/dentaku/ast/arithmetic.rb', line 267

def operator_spacing
  ""
end

#value(context = {}) ⇒ Object



259
260
261
# File 'lib/dentaku/ast/arithmetic.rb', line 259

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