Class: DoubleEntry::Reporting::Aggregate
- Inherits:
-
Object
- Object
- DoubleEntry::Reporting::Aggregate
- Defined in:
- lib/double_entry/reporting/aggregate.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#partner_account ⇒ Object
readonly
Returns the value of attribute partner_account.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Class Method Summary collapse
Instance Method Summary collapse
- #amount(force_recalculation = false) ⇒ Object
- #formatted_amount(value = amount) ⇒ Object
-
#initialize(function:, account:, code:, range:, partner_account: nil, filter: nil) ⇒ Aggregate
constructor
A new instance of Aggregate.
Constructor Details
#initialize(function:, account:, code:, range:, partner_account: nil, filter: nil) ⇒ Aggregate
Returns a new instance of Aggregate.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/double_entry/reporting/aggregate.rb', line 18 def initialize(function:, account:, code:, range:, partner_account: nil, filter: nil) @function = function.to_s fail AggregateFunctionNotSupported unless %w(sum count average).include?(@function) @account = account @code = code.try(:to_s) @range = range @partner_account = partner_account @filter = filter @currency = DoubleEntry::Account.currency(account) end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def account @account end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def code @code end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def currency @currency end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def filter @filter end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def function @function end |
#partner_account ⇒ Object (readonly)
Returns the value of attribute partner_account.
5 6 7 |
# File 'lib/double_entry/reporting/aggregate.rb', line 5 def partner_account @partner_account end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
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:, partner_account: nil, filter: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/double_entry/reporting/aggregate.rb', line 7 def self.formatted_amount(function:, account:, code:, range:, partner_account: nil, filter: nil) new( function: function, account: account, code: code, range: range, partner_account: partner_account, filter: filter, ).formatted_amount end |
Instance Method Details
#amount(force_recalculation = false) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/double_entry/reporting/aggregate.rb', line 30 def amount(force_recalculation = false) if force_recalculation clear_old_aggregates calculate else retrieve || calculate end end |
#formatted_amount(value = amount) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/double_entry/reporting/aggregate.rb', line 39 def formatted_amount(value = amount) value ||= 0 if function == 'count' value else Money.new(value, currency) end end |