Class: BCDice::CommonCommand::RerollDice::Node::RerollCondition
- Inherits:
-
Object
- Object
- BCDice::CommonCommand::RerollDice::Node::RerollCondition
- Defined in:
- lib/bcdice/common_command/reroll_dice/node.rb
Overview
振り足し条件を表すクラス。
Instance Attribute Summary collapse
-
#cmp_op ⇒ Symbol
readonly
比較演算子.
-
#threshold ⇒ Integer
readonly
振り足しの閾値.
Instance Method Summary collapse
-
#initialize(cmp_op, threshold) ⇒ RerollCondition
constructor
A new instance of RerollCondition.
-
#reroll?(value) ⇒ Boolean
振り足しを行うべきか.
-
#valid?(sides) ⇒ Boolean
振り足し条件が妥当か.
Constructor Details
#initialize(cmp_op, threshold) ⇒ RerollCondition
Returns a new instance of RerollCondition.
132 133 134 135 |
# File 'lib/bcdice/common_command/reroll_dice/node.rb', line 132 def initialize(cmp_op, threshold) @cmp_op = cmp_op @threshold = threshold end |
Instance Attribute Details
#cmp_op ⇒ Symbol (readonly)
Returns 比較演算子.
126 127 128 |
# File 'lib/bcdice/common_command/reroll_dice/node.rb', line 126 def cmp_op @cmp_op end |
#threshold ⇒ Integer (readonly)
Returns 振り足しの閾値.
128 129 130 |
# File 'lib/bcdice/common_command/reroll_dice/node.rb', line 128 def threshold @threshold end |
Instance Method Details
#reroll?(value) ⇒ Boolean
Returns 振り足しを行うべきか.
160 161 162 |
# File 'lib/bcdice/common_command/reroll_dice/node.rb', line 160 def reroll?(value) value.send(@cmp_op, @threshold) end |
#valid?(sides) ⇒ Boolean
Returns 振り足し条件が妥当か.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# 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 |