Class: Dicechucker::Diesheet
- Inherits:
-
Object
- Object
- Dicechucker::Diesheet
- Defined in:
- lib/dicechucker/diesheet.rb
Instance Attribute Summary collapse
-
#diesets ⇒ Object
Returns the value of attribute diesets.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(key, dieset) ⇒ Object
-
#initialize(diesets = {}) ⇒ Diesheet
constructor
A new instance of Diesheet.
- #remove(key) ⇒ Object
- #results ⇒ Object
- #roll ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(diesets = {}) ⇒ Diesheet
Returns a new instance of Diesheet.
6 7 8 9 10 11 |
# File 'lib/dicechucker/diesheet.rb', line 6 def initialize(diesets = {}) @diesets = {} diesets.each do |key, value| @diesets[key] = Dicechucker.parse(value) end end |
Instance Attribute Details
#diesets ⇒ Object
Returns the value of attribute diesets.
4 5 6 |
# File 'lib/dicechucker/diesheet.rb', line 4 def diesets @diesets end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 |
# File 'lib/dicechucker/diesheet.rb', line 13 def [](key) @diesets[key] end |
#add(key, dieset) ⇒ Object
17 18 19 |
# File 'lib/dicechucker/diesheet.rb', line 17 def add(key, dieset) @diesets[key] = Dicechucker.parse(dieset) end |
#remove(key) ⇒ Object
21 22 23 |
# File 'lib/dicechucker/diesheet.rb', line 21 def remove(key) @diesets.delete(key) end |
#results ⇒ Object
31 32 33 |
# File 'lib/dicechucker/diesheet.rb', line 31 def results to_s end |
#roll ⇒ Object
25 26 27 28 29 |
# File 'lib/dicechucker/diesheet.rb', line 25 def roll @diesets.each_value do |value| value.roll end end |
#to_s ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/dicechucker/diesheet.rb', line 35 def to_s output = "" @diesets.each do |key, value| output << "#{key.to_s} = #{value.total.to_s}\n" end output end |