Class: Randsum::RollReport
- Inherits:
-
Object
- Object
- Randsum::RollReport
- Defined in:
- lib/randsum/roll_report.rb
Instance Method Summary collapse
- #die ⇒ Object
- #drop(quantity:, extremity:) ⇒ Object
- #drop_highest(quantity = 1) ⇒ Object
- #drop_lowest(quantity = 1) ⇒ Object
-
#initialize(roll) ⇒ RollReport
constructor
A new instance of RollReport.
- #inspect ⇒ Object
- #quantity ⇒ Object
- #rolls ⇒ Object
- #sides ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(roll) ⇒ RollReport
Returns a new instance of RollReport.
4 5 6 |
# File 'lib/randsum/roll_report.rb', line 4 def initialize(roll) @roll = roll end |
Instance Method Details
#die ⇒ Object
24 25 26 |
# File 'lib/randsum/roll_report.rb', line 24 def die roll.die end |
#drop(quantity:, extremity:) ⇒ Object
40 41 42 43 44 |
# File 'lib/randsum/roll_report.rb', line 40 def drop(quantity:, extremity:) return RollReport.new( roll.drop(quantity: quantity, extremity: extremity) ) end |
#drop_highest(quantity = 1) ⇒ Object
52 53 54 55 56 |
# File 'lib/randsum/roll_report.rb', line 52 def drop_highest(quantity = 1) return RollReport.new( roll.drop(quantity: quantity, extremity: :highest) ) end |
#drop_lowest(quantity = 1) ⇒ Object
46 47 48 49 50 |
# File 'lib/randsum/roll_report.rb', line 46 def drop_lowest(quantity = 1) return RollReport.new( roll.drop(quantity: quantity, extremity: :lowest) ) end |
#inspect ⇒ Object
8 9 10 |
# File 'lib/randsum/roll_report.rb', line 8 def inspect to_s end |
#quantity ⇒ Object
36 37 38 |
# File 'lib/randsum/roll_report.rb', line 36 def quantity @_quantity ||= rolls.count end |
#rolls ⇒ Object
28 29 30 |
# File 'lib/randsum/roll_report.rb', line 28 def rolls @_rolls ||= roll.result end |
#sides ⇒ Object
20 21 22 |
# File 'lib/randsum/roll_report.rb', line 20 def sides die.sides end |
#to_i ⇒ Object
16 17 18 |
# File 'lib/randsum/roll_report.rb', line 16 def to_i total end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/randsum/roll_report.rb', line 12 def to_s "You rolled #{quantity} #{die}, and got #{total}. (#{roll})" end |
#total ⇒ Object
32 33 34 |
# File 'lib/randsum/roll_report.rb', line 32 def total @_total ||= rolls.inject(:+) end |