Class: BagOfHolding::Dice::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/bag_of_holding/dice/pool.rb

Overview

Internal: Contains information about the number of dice in a pool, the description of those dice and a label if it has one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count: nil, die: nil, label: nil, keep: nil) ⇒ Pool

Returns a new instance of Pool.



8
9
10
11
12
13
# File 'lib/bag_of_holding/dice/pool.rb', line 8

def initialize(count: nil, die: nil, label: nil, keep: nil)
  self.count  = count
  self.die    = die
  self.label  = label
  self.keep   = keep
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



6
7
8
# File 'lib/bag_of_holding/dice/pool.rb', line 6

def count
  @count
end

#dieObject

Returns the value of attribute die.



6
7
8
# File 'lib/bag_of_holding/dice/pool.rb', line 6

def die
  @die
end

#keepObject

Returns the value of attribute keep.



6
7
8
# File 'lib/bag_of_holding/dice/pool.rb', line 6

def keep
  @keep
end

#labelObject

Returns the value of attribute label.



6
7
8
# File 'lib/bag_of_holding/dice/pool.rb', line 6

def label
  @label
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bag_of_holding/dice/pool.rb', line 15

def ==(other)
  begin
    return false unless count == other.count
    return false unless die == other.die
    return false unless label == other.label
  rescue NoMethodError
    return false
  end

  true
end

#rollObject



27
28
29
30
31
# File 'lib/bag_of_holding/dice/pool.rb', line 27

def roll
  BagOfHolding::Dice::PoolResult.new die_results: die_results,
                                     value: value,
                                     pool: self
end

#to_sObject



33
34
35
# File 'lib/bag_of_holding/dice/pool.rb', line 33

def to_s
  "#{count}#{die}"
end