Class: DoubleEntry::Reporting::Aggregate Private
- Inherits:
-
Object
- Object
- DoubleEntry::Reporting::Aggregate
- Defined in:
- lib/double_entry/reporting/aggregate.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #account ⇒ Object readonly private
- #code ⇒ Object readonly private
- #currency ⇒ Object readonly private
- #filter ⇒ Object readonly private
- #function ⇒ Object readonly private
- #range ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #amount(force_recalculation = false) ⇒ Object private
- #formatted_amount(value = amount) ⇒ Object private
-
#initialize(function, account, code, range, options = {}) ⇒ Aggregate
constructor
private
A new instance of Aggregate.
Constructor Details
#initialize(function, account, code, range, options = {}) ⇒ Aggregate
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Aggregate.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/double_entry/reporting/aggregate.rb', line 11 def initialize(function, account, code, range, = {}) @function = function.to_s fail AggregateFunctionNotSupported unless %w(sum count average).include?(@function) @account = account @code = code ? code.to_s : nil @range = range @filter = [:filter] @currency = DoubleEntry::Account.currency(account) end |
Instance Attribute Details
#account ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def account @account end |
#code ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def code @code end |
#currency ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def currency @currency end |
#filter ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def filter @filter end |
#function ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def function @function end |
#range ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def range @range end |
Class Method Details
.formatted_amount(function, account, code, range, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/double_entry/reporting/aggregate.rb', line 7 def self.formatted_amount(function, account, code, range, = {}) new(function, account, code, range, ).formatted_amount end |
Instance Method Details
#amount(force_recalculation = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 29 |
# File 'lib/double_entry/reporting/aggregate.rb', line 22 def amount(force_recalculation = false) if force_recalculation clear_old_aggregates calculate else retrieve || calculate end end |
#formatted_amount(value = amount) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 37 38 |
# File 'lib/double_entry/reporting/aggregate.rb', line 31 def formatted_amount(value = amount) value ||= 0 if function == 'count' value else Money.new(value, currency) end end |