Class: Dentaku::AST::Modulo
- Inherits:
-
Arithmetic
- Object
- Node
- Operation
- Arithmetic
- Dentaku::AST::Modulo
- Defined in:
- lib/dentaku/ast/arithmetic.rb
Instance Attribute Summary
Attributes inherited from Operation
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies(context = {}) ⇒ Object
-
#initialize(left, right = nil) ⇒ Modulo
constructor
A new instance of Modulo.
- #operator ⇒ Object
- #percent? ⇒ Boolean
- #valid_left? ⇒ Boolean
- #value(context = {}) ⇒ Object
Methods inherited from Arithmetic
Methods inherited from Operation
Constructor Details
#initialize(left, right = nil) ⇒ Modulo
Returns a new instance of Modulo.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/dentaku/ast/arithmetic.rb', line 144 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
.arity ⇒ Object
135 136 137 |
# File 'lib/dentaku/ast/arithmetic.rb', line 135 def self.arity @arity end |
.peek(input) ⇒ Object
139 140 141 142 |
# File 'lib/dentaku/ast/arithmetic.rb', line 139 def self.peek(input) @arity = 1 @arity = 2 if input.length > 1 end |
.precedence ⇒ Object
186 187 188 |
# File 'lib/dentaku/ast/arithmetic.rb', line 186 def self.precedence 20 end |
Instance Method Details
#dependencies(context = {}) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/dentaku/ast/arithmetic.rb', line 162 def dependencies(context = {}) if percent? @right.dependencies(context) else super end end |
#operator ⇒ Object
182 183 184 |
# File 'lib/dentaku/ast/arithmetic.rb', line 182 def operator :% end |
#percent? ⇒ Boolean
170 171 172 |
# File 'lib/dentaku/ast/arithmetic.rb', line 170 def percent? left.nil? end |
#valid_left? ⇒ Boolean
190 191 192 |
# File 'lib/dentaku/ast/arithmetic.rb', line 190 def valid_left? valid_node?(left) || left.nil? end |
#value(context = {}) ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/dentaku/ast/arithmetic.rb', line 174 def value(context = {}) if percent? cast(right.value(context)) * 0.01 else super end end |