Class: DiceBag::Result
- Inherits:
-
Object
- Object
- DiceBag::Result
- 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
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(label, total, sections) ⇒ Result
constructor
A new instance of Result.
- #to_s ⇒ Object
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
#label ⇒ Object (readonly)
Returns the value of attribute label.
8 9 10 |
# File 'lib/dicebag/result.rb', line 8 def label @label end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
10 11 12 |
# File 'lib/dicebag/result.rb', line 10 def sections @sections end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
9 10 11 |
# File 'lib/dicebag/result.rb', line 9 def total @total end |
Instance Method Details
#each ⇒ Object
18 19 20 |
# File 'lib/dicebag/result.rb', line 18 def each sections.each { |section| yield section } end |
#to_s ⇒ Object
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 |