class BCDice::CommonCommand::AddDice::Node::DivideBase

除算ノードの基底クラス

定数 ROUNDING_METHOD で端数処理方法を示す記号 ( +'U'+, +'R'+, +''+ ) を定義すること。 また、除算および端数処理を行う divide_and_round メソッドを実装すること。

Public Class Methods

new(lhs, rhs) click to toggle source

ノードを初期化する @param [Object] lhs 左のオペランドのノード @param [Object] rhs 右のオペランドのノード

# File lib/bcdice/common_command/add_dice/node.rb, line 199
def initialize(lhs, rhs)
  super(lhs, :/, rhs)
end

Public Instance Methods

expr(game_system) click to toggle source

文字列に変換する

通常の結果の末尾に、端数処理方法を示す記号を付加する。

@return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 208
def expr(game_system)
  "#{super(game_system)}#{rounding_method}"
end
output() click to toggle source

メッセージへの出力を返す

通常の結果の末尾に、端数処理方法を示す記号を付加する。

@return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 217
def output
  "#{super}#{rounding_method}"
end

Private Instance Methods

calc(lhs, rhs, round_type) click to toggle source

演算を行う @param lhs [Integer] 左のオペランド @param rhs [Integer] 右のオペランド @param round_type [Symbol] ゲームシステムの端数処理設定 @return [Integer] 演算の結果

# File lib/bcdice/common_command/add_dice/node.rb, line 240
def calc(lhs, rhs, round_type)
  if rhs.zero?
    return 1
  end

  return divide_and_round(lhs, rhs, round_type)
end
divide_and_round(dividend, divisor, round_type) click to toggle source

除算および端数処理を行う @param dividend [Integer] 被除数 @param divisor [Integer] 除数(0以外) @param round_type [Symbol] ゲームシステムの端数処理設定 @return [Integer]

# File lib/bcdice/common_command/add_dice/node.rb, line 253
def divide_and_round(dividend, divisor, round_type)
  raise NotImplementedError
end
op_for_s_exp() click to toggle source

S式で使う演算子の表現を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 231
def op_for_s_exp
  "#{@op}#{rounding_method}"
end
rounding_method() click to toggle source

端数処理方法を示す記号を返す @return [String]

# File lib/bcdice/common_command/add_dice/node.rb, line 225
def rounding_method
  self.class::ROUNDING_METHOD
end