Class: Randsum::RollReport

Inherits:
Object
  • Object
show all
Defined in:
lib/randsum/roll_report.rb

Instance Method Summary collapse

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

#dieObject



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

#inspectObject



8
9
10
# File 'lib/randsum/roll_report.rb', line 8

def inspect
  to_s
end

#quantityObject



36
37
38
# File 'lib/randsum/roll_report.rb', line 36

def quantity
  @_quantity ||= rolls.count
end

#rollsObject



28
29
30
# File 'lib/randsum/roll_report.rb', line 28

def rolls
  @_rolls ||= roll.result
end

#sidesObject



20
21
22
# File 'lib/randsum/roll_report.rb', line 20

def sides
  die.sides
end

#to_iObject



16
17
18
# File 'lib/randsum/roll_report.rb', line 16

def to_i
  total
end

#to_sObject



12
13
14
# File 'lib/randsum/roll_report.rb', line 12

def to_s
  "You rolled #{quantity} #{die}, and got #{total}. (#{roll})"
end

#totalObject



32
33
34
# File 'lib/randsum/roll_report.rb', line 32

def total
  @_total ||= rolls.inject(:+)
end