Class: DoubleEntry::Reporting::Aggregate Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, , code, range, options = {})
  @function = function.to_s
  fail AggregateFunctionNotSupported unless %w(sum count average).include?(@function)

  @account = 
  @code = code ? code.to_s : nil
  @range = range
  @filter = options[:filter]
  @currency = DoubleEntry::Account.currency()
end

Instance Attribute Details

#accountObject (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
end

#codeObject (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

#currencyObject (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

#filterObject (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

#functionObject (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

#rangeObject (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, , code, range, options = {})
  new(function, , code, range, options).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