class DoubleEntry::Reporting::LineAggregateFilter
Public Class Methods
new(account:, partner_account:, code:, range:, filter_criteria:)
click to toggle source
# File lib/double_entry/reporting/line_aggregate_filter.rb, line 6 def initialize(account:, partner_account:, code:, range:, filter_criteria:) @account = account @partner_account = partner_account @code = code @range = range @filter_criteria = filter_criteria || [] end
Public Instance Methods
filter()
click to toggle source
# File lib/double_entry/reporting/line_aggregate_filter.rb, line 14 def filter @collection ||= apply_filters end
Private Instance Methods
apply_filter_criteria()
click to toggle source
a lot of the trickier reports will use filters defined in filter_criteria to bring in data from other tables. For example:
filter_criteria = [ # an example of calling a named scope called with arguments { :scope => { :name => :ten_dollar_purchases_by_category, :arguments => [:cat_videos, :cat_pictures] } }, # an example of calling a named scope with no arguments { :scope => { :name => :ten_dollar_purchases } }, # an example of providing multiple metadatum criteria to filter on { :metadata => { :meme => :business_cat, :category => :fun_times, } } ]
# File lib/double_entry/reporting/line_aggregate_filter.rb, line 56 def apply_filter_criteria @filter_criteria.reduce(DoubleEntry::Line) do |collection, filter| if filter[:scope].present? filter_by_scope(collection, filter[:scope]) elsif filter[:metadata].present? filter_by_metadata(collection, filter[:metadata]) else collection end end end
apply_filters()
click to toggle source
# File lib/double_entry/reporting/line_aggregate_filter.rb, line 20 def apply_filters collection = apply_filter_criteria. where(:account => @account). where(:created_at => @range.start..@range.finish) collection = collection.where(:code => @code) if @code collection = collection.where(:partner_account => @partner_account) if @partner_account collection end
filter_by_metadata(collection, metadata)
click to toggle source
# File lib/double_entry/reporting/line_aggregate_filter.rb, line 72 def filter_by_metadata(collection, metadata) DoubleEntry::Reporting::LineMetadataFilter.filter(collection: collection, metadata: metadata) end
filter_by_scope(collection, scope)
click to toggle source
# File lib/double_entry/reporting/line_aggregate_filter.rb, line 68 def filter_by_scope(collection, scope) collection.public_send(scope[:name], *scope[:arguments]) end