Class: Dentaku::AST::Modulo

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, #type

Constructor Details

#initialize(left, right = nil) ⇒ Modulo

Returns a new instance of Modulo.



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/dentaku/ast/arithmetic.rb', line 188

def initialize(left, right = nil)
  if right
    @left  = left
    @right = right
  else
    @right = left
  end

  unless valid_left?
    raise NodeError.new(%i[numeric nil], left.type, :left),
          "#{self.class} requires numeric operands or nil"
  end
  unless valid_right?
    raise NodeError.new(:numeric, right.type, :right),
          "#{self.class} requires numeric operands"
  end
end

Class Method Details

.arityObject



179
180
181
# File 'lib/dentaku/ast/arithmetic.rb', line 179

def self.arity
  @arity
end

.peek(input) ⇒ Object



183
184
185
186
# File 'lib/dentaku/ast/arithmetic.rb', line 183

def self.peek(input)
  @arity = 1
  @arity = 2 if input.length > 1
end

.precedenceObject



230
231
232
# File 'lib/dentaku/ast/arithmetic.rb', line 230

def self.precedence
  20
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/dentaku/ast/arithmetic.rb', line 206

def dependencies(context = {})
  if percent?
    @right.dependencies(context)
  else
    super
  end
end

#operatorObject



226
227
228
# File 'lib/dentaku/ast/arithmetic.rb', line 226

def operator
  :%
end

#percent?Boolean

Returns:

  • (Boolean)


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

def percent?
  left.nil?
end

#valid_left?Boolean

Returns:

  • (Boolean)


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

def valid_left?
  valid_node?(left) || left.nil?
end

#value(context = {}) ⇒ Object



218
219
220
221
222
223
224
# File 'lib/dentaku/ast/arithmetic.rb', line 218

def value(context = {})
  if percent?
    cast(right.value(context)) * 0.01
  else
    super
  end
end