class BCDice::CommonCommand::RerollDice::Node::RerollCondition

振り足し条件を表すクラス。

Attributes

cmp_op[R]

@return [Symbol] 比較演算子

threshold[R]

@return [Integer] 振り足しの閾値

Public Class Methods

new(cmp_op, threshold) click to toggle source

@param cmp_op [Symbol] 比較演算子 @param threshold [Integer] 振り足しの閾値

# File lib/bcdice/common_command/reroll_dice/node.rb, line 132
def initialize(cmp_op, threshold)
  @cmp_op = cmp_op
  @threshold = threshold
end

Public Instance Methods

reroll?(value) click to toggle source

@param value [Integer] 出目 @return [Boolean] 振り足しを行うべきか

# File lib/bcdice/common_command/reroll_dice/node.rb, line 160
def reroll?(value)
  value.send(@cmp_op, @threshold)
end
valid?(sides) click to toggle source

@param sides [Integer] ダイスの面数 @return [Boolean] 振り足し条件が妥当か

# File lib/bcdice/common_command/reroll_dice/node.rb, line 139
def valid?(sides)
  return false unless @threshold

  case @cmp_op
  when :<=
    @threshold < sides
  when :<
    @threshold <= sides
  when :>=
    @threshold > 1
  when :>
    @threshold >= 1
  when :'!='
    (1..sides).include?(@threshold)
  else # :==
    true
  end
end