Class: DiceBag::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/dicebag/result.rb

Overview

This class merely encapsulates the result, providing convience methods to access the results of each section if desired.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, total, sections) ⇒ Result

Returns a new instance of Result.



12
13
14
15
16
# File 'lib/dicebag/result.rb', line 12

def initialize(label, total, sections)
  @label    = label
  @total    = total
  @sections = sections
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/dicebag/result.rb', line 8

def label
  @label
end

#sectionsObject (readonly)

Returns the value of attribute sections.



10
11
12
# File 'lib/dicebag/result.rb', line 10

def sections
  @sections
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/dicebag/result.rb', line 9

def total
  @total
end

Instance Method Details

#eachObject



18
19
20
# File 'lib/dicebag/result.rb', line 18

def each
  sections.each { |section| yield section }
end

#to_sObject



22
23
24
25
26
# File 'lib/dicebag/result.rb', line 22

def to_s
  return "#{label}: #{total}" unless label.empty?

  total.to_s
end