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.



225
226
227
228
229
230
231
232
# File 'lib/dentaku/ast/arithmetic.rb', line 225

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



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

def self.arity
  1
end

.precedenceObject



250
251
252
# File 'lib/dentaku/ast/arithmetic.rb', line 250

def self.precedence
  30
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



234
235
236
# File 'lib/dentaku/ast/arithmetic.rb', line 234

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

#operatorObject



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

def operator
  :%
end

#operator_spacingObject



246
247
248
# File 'lib/dentaku/ast/arithmetic.rb', line 246

def operator_spacing
  ""
end

#value(context = {}) ⇒ Object



238
239
240
# File 'lib/dentaku/ast/arithmetic.rb', line 238

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