Class: Differential::Calculator::Group
- Inherits:
-
Object
- Object
- Differential::Calculator::Group
- Includes:
- HasTotals
- Defined in:
- lib/differential/calculator/group.rb
Overview
A Report has 0 or more Group objects and a Group has 0 or more Item objects. Report -> Group -> Item A Group is, as the name implies, a grouping of items. It is up to the consumer application to define how to group (i.e. group based on this attribute’s value or group based on these two attributes’ values.)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #add(record, side) ⇒ Object
-
#initialize(id) ⇒ Group
constructor
A new instance of Group.
- #items ⇒ Object
Methods included from HasTotals
Constructor Details
#initialize(id) ⇒ Group
Returns a new instance of Group.
22 23 24 25 26 |
# File 'lib/differential/calculator/group.rb', line 22 def initialize(id) raise ArgumentError, 'id is required' unless id @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/differential/calculator/group.rb', line 20 def id @id end |
Instance Method Details
#add(record, side) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/differential/calculator/group.rb', line 32 def add(record, side) raise ArgumentError, 'record is required' unless record raise ArgumentError, 'side is required' unless side raise ArgumentError, "mismatch: #{record.group_id} != #{id}" if id != record.group_id totals.add(record.value, side) upsert_item(record, side) self end |
#items ⇒ Object
28 29 30 |
# File 'lib/differential/calculator/group.rb', line 28 def items items_by_id.values end |