Method: DoubleEntry::Reporting#aggregate_array

Defined in:
lib/double_entry/reporting.rb

#aggregate_array(function, account, code, options = {}) ⇒ Array[Money/Fixnum]

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.

Perform an aggregate calculation on a set of transfers for an account and return the results in an array partitioned by a time range type.

The transfers included in the calculation can be limited by a time range and provided custom filters.

Examples:

Find the number of all $10 :save transfers in all :checking accounts per month for the entire year (Assume the year is 2014).

DoubleEntry.aggregate_array(:sum, :checking, :save, range_type: 'month', start: '2014-01-01', finish: '2014-12-31')

Parameters:

  • function (Symbol)

    The function to perform on the set of transfers. Valid functions are :sum, :count, and :average

  • account (Symbol)

    The symbol identifying the account to perform the aggregate calculation on. As specified in the account configuration.

  • code (Symbol)

    The application specific code for the type of transfer to perform an aggregate calculation on. As specified in the transfer configuration.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :filter (Array[Symbol], or Array[Hash<Symbol,Parameter>])

    A custom filter to apply before performing the aggregate calculation. Currently, filters must be monkey patched as scopes into the DoubleEntry::Line class in order to be used as filters, as the example shows. If the filter requires a parameter, it must be given in a Hash, otherwise pass an array with the symbol names for the defined scopes.

  • :range_type (String)

    The type of time range to return data for. For example, specifying 'month' will return an array of the resulting aggregate calculation for each month. Valid range_types are 'hour', 'day', 'week', 'month', and 'year'

  • :start (String)

    The start date for the time range to perform calculations in. The default start date is the start_of_business (can be specified in configuration). The format of the string must be as follows: 'YYYY-mm-dd'

  • :finish (String)

    The finish (or end) date for the time range to perform calculations in. The default finish date is the current date. The format of the string must be as follows: 'YYYY-mm-dd'

Returns:

  • (Array[Money/Fixnum])

    Returns an array of Money objects for :sum and :average calculations, or an array of Fixnum for :count calculations. The array is indexed by the range_type. For example, if range_type is specified as 'month', each index in the array will represent a month.

Raises:



105
106
107
# File 'lib/double_entry/reporting.rb', line 105

def aggregate_array(function, , code, options = {})
  AggregateArray.new(function, , code, options)
end