summaryrefslogtreecommitdiff
path: root/app/lib/dice/result.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/dice/result.rb')
-rw-r--r--app/lib/dice/result.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/lib/dice/result.rb b/app/lib/dice/result.rb
new file mode 100644
index 0000000..103a282
--- /dev/null
+++ b/app/lib/dice/result.rb
@@ -0,0 +1,32 @@
+class Dice::Result
+ attr_reader :rolls
+
+ def initialize
+ @rolls = []
+ end
+
+ # @param other [Dice::Result]
+ def ==(other)
+ sides == other.sides && face == other.face
+ end
+
+ # @param roll [Dice::Roll]
+ def add_roll(roll)
+ @rolls << roll
+ end
+
+ # @return [Integer]
+ def total
+ @rolls.sum(&:face)
+ end
+
+ def increase_sides_below_max(max_value, increase_by)
+ @rolls.each do |roll|
+ roll.increase_side_below_max(max_value, increase_by)
+ end
+ end
+
+ def to_s
+ "#{total} (#{@rolls.map(&:face).join(', ')})"
+ end
+end