Class: Dicechucker::Diesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/dicechucker/diesheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#diesetsObject

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

#resultsObject



31
32
33
# File 'lib/dicechucker/diesheet.rb', line 31

def results
  to_s
end

#rollObject



25
26
27
28
29
# File 'lib/dicechucker/diesheet.rb', line 25

def roll
  @diesets.each_value do |value|
    value.roll
  end
end

#to_sObject



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