Class: BCDice::CommonCommand::Calc::Node::Command
- Inherits:
-
Object
- Object
- BCDice::CommonCommand::Calc::Node::Command
- Defined in:
- lib/bcdice/common_command/calc/node.rb
Instance Method Summary collapse
- #eval(round_type) ⇒ Object
-
#initialize(secret:, expr:) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(secret:, expr:) ⇒ Command
Returns a new instance of Command.
10 11 12 13 |
# File 'lib/bcdice/common_command/calc/node.rb', line 10 def initialize(secret:, expr:) @secret = secret @expr = expr end |
Instance Method Details
#eval(round_type) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bcdice/common_command/calc/node.rb', line 15 def eval(round_type) value = begin @expr.eval(round_type) rescue ZeroDivisionError "ゼロ除算が発生したため計算できませんでした" end output = if @expr.is_a?(Arithmetic::Node::Parenthesis) @expr.output else "(#{@expr.output})" end Result.new.tap do |r| r.secret = @secret r.text = "c#{output} > #{value}" end end |