Class: DiceBag::Result
- Inherits:
-
Object
- Object
- DiceBag::Result
- Includes:
- Comparable
- 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
- #<=>(other) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(label, total, sections) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(label, total, sections) ⇒ Result
Returns a new instance of Result.
11 12 13 14 15 |
# File 'lib/dicebag/result.rb', line 11 def initialize(label, total, sections) @label = label @total = total @sections = sections end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/dicebag/result.rb', line 7 def label @label end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
9 10 11 |
# File 'lib/dicebag/result.rb', line 9 def sections @sections end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
8 9 10 |
# File 'lib/dicebag/result.rb', line 8 def total @total end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 |
# File 'lib/dicebag/result.rb', line 31 def <=>(other) @total <=> other.total end |
#each(&block) ⇒ Object
17 18 19 |
# File 'lib/dicebag/result.rb', line 17 def each(&block) sections.each { |section| block.call section } end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/dicebag/result.rb', line 27 def inspect "<#{self.class.name} #{self}>" end |
#to_s ⇒ Object
21 22 23 24 25 |
# File 'lib/dicebag/result.rb', line 21 def to_s return "#{label}: #{total}" unless label.empty? total.to_s end |