Class: Randsum::Roll
- Inherits:
-
Object
- Object
- Randsum::Roll
- Defined in:
- lib/randsum/roll.rb
Instance Attribute Summary collapse
-
#die ⇒ Object
readonly
Returns the value of attribute die.
-
#quantity ⇒ Object
(also: #length, #count)
readonly
Returns the value of attribute quantity.
-
#result ⇒ Object
(also: #rolls)
readonly
Returns the value of attribute result.
-
#sides ⇒ Object
readonly
Returns the value of attribute sides.
-
#total ⇒ Object
(also: #to_i)
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #beats?(check_value) ⇒ Boolean
- #double_all(target) ⇒ Object
- #drop(quantity:, extremity:) ⇒ Object
- #drop_highest(quantity = 1) ⇒ Object
- #drop_lowest(quantity = 1) ⇒ Object
-
#initialize(die:, quantity:, result: nil) ⇒ Roll
constructor
A new instance of Roll.
- #meets?(meet_value) ⇒ Boolean
- #replace(target, with:) ⇒ Object
- #reroll ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(die:, quantity:, result: nil) ⇒ Roll
Returns a new instance of Roll.
13 14 15 16 17 18 |
# File 'lib/randsum/roll.rb', line 13 def initialize(die:, quantity:, result: nil) @die = die @quantity = quantity @sides = die.sides @result = result || roll! end |
Instance Attribute Details
#die ⇒ Object (readonly)
Returns the value of attribute die.
3 4 5 |
# File 'lib/randsum/roll.rb', line 3 def die @die end |
#quantity ⇒ Object (readonly) Also known as: length, count
Returns the value of attribute quantity.
3 4 5 |
# File 'lib/randsum/roll.rb', line 3 def quantity @quantity end |
#result ⇒ Object (readonly) Also known as: rolls
Returns the value of attribute result.
3 4 5 |
# File 'lib/randsum/roll.rb', line 3 def result @result end |
#sides ⇒ Object (readonly)
Returns the value of attribute sides.
3 4 5 |
# File 'lib/randsum/roll.rb', line 3 def sides @sides end |
#total ⇒ Object (readonly) Also known as: to_i
Returns the value of attribute total.
3 4 5 |
# File 'lib/randsum/roll.rb', line 3 def total @total end |
Class Method Details
.roll(num, d:) ⇒ Object
9 10 11 |
# File 'lib/randsum/roll.rb', line 9 def self.roll(num, d:) new(die: Die.new(d), quantity: num) end |
Instance Method Details
#beats?(check_value) ⇒ Boolean
30 31 32 |
# File 'lib/randsum/roll.rb', line 30 def beats?(check_value) total > check_value end |
#double_all(target) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/randsum/roll.rb', line 46 def double_all(target) Replacer.for( target: target, with: ReplacerValue::DOUBLE, roll: self ).filter end |
#drop(quantity:, extremity:) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/randsum/roll.rb', line 62 def drop(quantity:,extremity:) Dropper.for( quantity: quantity, extremity: extremity, roll: self ).filter end |
#drop_highest(quantity = 1) ⇒ Object
74 75 76 |
# File 'lib/randsum/roll.rb', line 74 def drop_highest(quantity = 1) drop(quantity: quantity, extremity: :highest) end |
#drop_lowest(quantity = 1) ⇒ Object
70 71 72 |
# File 'lib/randsum/roll.rb', line 70 def drop_lowest(quantity = 1) drop(quantity: quantity, extremity: :lowest) end |
#meets?(meet_value) ⇒ Boolean
34 35 36 |
# File 'lib/randsum/roll.rb', line 34 def meets?(meet_value) total >= meet_value end |
#replace(target, with:) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/randsum/roll.rb', line 38 def replace(target, with:) Replacer.for( target: target, with: with, roll: self ).filter end |
#reroll ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/randsum/roll.rb', line 54 def reroll Replacer.for( target: ReplacerTarget::ALL, with: ReplacerValue::REROLL, roll: self ).filter end |
#to_s ⇒ Object Also known as: inspect
20 21 22 |
# File 'lib/randsum/roll.rb', line 20 def to_s "You rolled #{count} #{die}, and got #{total}. (Rolls: #{result})" end |