Class: Cinch::Plugins::Dicebag::Bag
- Inherits:
-
Object
- Object
- Cinch::Plugins::Dicebag::Bag
- Defined in:
- lib/cinch/plugins/dicebag/bag.rb
Overview
Class to handle rolling of a preset bag of dice.
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#dice ⇒ Object
Returns the value of attribute dice.
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
-
#initialize(dice_hash) ⇒ Bag
constructor
Create a new bag.
-
#roll ⇒ Object
Roll the bag of dice, this will roll the dice and update the current score and count.
-
#size ⇒ String
Simple method to return a flavor text ‘size’ description based on how many dice you happened to get in your dicebag roll.
- #stats ⇒ Object
Constructor Details
#initialize(dice_hash) ⇒ Bag
Create a new bag
12 13 14 15 16 17 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 12 def initialize(dice_hash) fail unless good_hash?(dice_hash) @dice = dice_hash @count = 0 @score = 0 end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
6 7 8 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 6 def count @count end |
#dice ⇒ Object
Returns the value of attribute dice.
6 7 8 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 6 def dice @dice end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 6 def score @score end |
Instance Method Details
#roll ⇒ Object
Roll the bag of dice, this will roll the dice and update the current
score and count
30 31 32 33 34 35 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 30 def roll dice = die_array @score = Die.roll(dice) @count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+) return self end |
#size ⇒ String
Simple method to return a flavor text ‘size’ description based on
how many dice you happened to get in your dicebag roll.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 41 def size case when @count < 1000 then 'tiny' when @count < 2000 then 'small' when @count < 3000 then 'medium' when @count < 4000 then 'large' when @count < 5000 then 'hefty' else 'massive' end end |
#stats ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/cinch/plugins/dicebag/bag.rb', line 19 def stats max_score = @dice.keys.inject(0) { |sum, x| sum + (x * @dice[x]) } min_score = @dice.keys.count max_count = @dice.values.inject(0) { |sum, x| sum + x } min_count = @dice.keys.count { min_count: min_count, max_count: max_count, min_score: min_score, max_score: max_score } end |