Class: Aggregator
- Defined in:
- lib/guerrilla_patch/aggregate_by_type/aggregator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(amount) ⇒ Object
- #add_full_precision(amount) ⇒ Object
- #subtract(amount) ⇒ Object
- #subtract_full_precision(amount) ⇒ Object
- #total ⇒ Object
- #total_by_type ⇒ Object
Class Method Details
.aggregate(&block) ⇒ Object
5 6 7 8 9 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 5 def self.aggregate(&block) agregator = Aggregator.new block.call(agregator) return Amount.new(agregator.total,agregator.total_by_type) end |
.aggregate_full_precistion(&block) ⇒ Object
11 12 13 14 15 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 11 def self.aggregate_full_precistion(&block) agregator = Aggregator.new block.call(agregator) return Amount.new(agregator.total,agregator.total_by_type) end |
Instance Method Details
#add(amount) ⇒ Object
17 18 19 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 17 def add(amount) total_list << Aggregator.prepare(amount) end |
#add_full_precision(amount) ⇒ Object
21 22 23 24 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 21 def add_full_precision(amount) raise "Full precision can be done only on amount class. Class sended was: #{amount.class} with value: #{amount.inspect}" if amount.class != Amount total_list << amount.by_type end |
#subtract(amount) ⇒ Object
26 27 28 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 26 def subtract(amount) add(amount.negative) end |
#subtract_full_precision(amount) ⇒ Object
30 31 32 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 30 def subtract_full_precision(amount) add_full_precision(amount.negative) end |
#total ⇒ Object
34 35 36 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 34 def total (by_type? ? total_by_type : total_list).sum_me end |
#total_by_type ⇒ Object
38 39 40 |
# File 'lib/guerrilla_patch/aggregate_by_type/aggregator.rb', line 38 def total_by_type Aggregator.agregate_by_type(total_list) end |