Class: Differential::Calculator::Item
- Inherits:
-
Object
- Object
- Differential::Calculator::Item
- Defined in:
- lib/differential/calculator/item.rb
Overview
Consider this as being line-level and is the lowest point of calculation. Ultimately a Report object will turn all added Record objects into Item objects (placed in Group objects.)
Constant Summary
Constants included from Side
Instance Attribute Summary collapse
-
#a_records ⇒ Object
readonly
Returns the value of attribute a_records.
-
#b_records ⇒ Object
readonly
Returns the value of attribute b_records.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #add(record, side) ⇒ Object
-
#initialize(id) ⇒ Item
constructor
A new instance of Item.
Methods included from HasTotals
Constructor Details
#initialize(id) ⇒ Item
Returns a new instance of Item.
21 22 23 24 25 26 27 |
# File 'lib/differential/calculator/item.rb', line 21 def initialize(id) raise ArgumentError, 'id is required' unless id @id = id @a_records = [] @b_records = [] end |
Instance Attribute Details
#a_records ⇒ Object (readonly)
Returns the value of attribute a_records.
19 20 21 |
# File 'lib/differential/calculator/item.rb', line 19 def a_records @a_records end |
#b_records ⇒ Object (readonly)
Returns the value of attribute b_records.
19 20 21 |
# File 'lib/differential/calculator/item.rb', line 19 def b_records @b_records end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
19 20 21 |
# File 'lib/differential/calculator/item.rb', line 19 def id @id end |
Instance Method Details
#add(record, side) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/differential/calculator/item.rb', line 29 def add(record, side) raise ArgumentError, 'record is required' unless record raise ArgumentError, 'side is required' unless side raise ArgumentError, "mismatch: #{record.id} != #{id}" if id != record.id totals.add(record.value, side) account_for_record(record, side) self end |