module RockBooks::JournalEntryFilters

Public Instance Methods

account_code(account_code) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 48
def account_code(account_code)
  ->(entry) do
    entry.acct_amounts.map(&:code).detect { |code| code == account_code }
  end
end
all(*filters) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 74
def all(*filters)
  ->(entry) { filters.all? { |filter| filter.(entry) } }
end
any(*filters) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 79
def any(*filters)
  ->(entry) { filters.any? { |filter| filter.(entry) } }
end
date_in_range(start_date, end_date) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 67
def date_in_range(start_date, end_date)
  start_date = to_date(start_date)
  end_date = to_date(end_date)
  ->(entry) { entry.date >= start_date && entry.date <= end_date }
end
date_on_or_after(date) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 55
def date_on_or_after(date)
  ->(entry) { entry.date >= to_date(date) }

end
date_on_or_before(date) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 61
def date_on_or_before(date)
  date = to_date(date)
  ->(entry) { entry.date <= date }
end
day(target_year, target_month, target_day) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 41
def day(target_year, target_month, target_day)
  ->(entry) do
    entry.date.year == target_year && entry.date.month == target_month && entry.date.day == target_day
  end
end
filter(entries, entry_filter) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 9
def filter(entries, entry_filter)
  entries.select { |entry| entry_filter.(entry) }
end
month(target_year, target_month) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 34
def month(target_year, target_month)
  ->(entry) do
    entry.date.year == target_year && entry.date.month == target_month
  end
end
none(*filters) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 84
def none(*filters)
  ->(entry) { filters.none? { |filter| filter.(entry) } }
end
null_filter() click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 24
def null_filter
  ->(entry) { true }
end
to_date(string_or_date_object) click to toggle source

Dates can be provided as a Ruby Date object, or as a string that will be converted to date (yyyy-mm-dd).

# File lib/rock_books/filters/journal_entry_filters.rb, line 15
def to_date(string_or_date_object)
  if string_or_date_object.is_a?(String)
    Date.iso8601(string_or_date_object)
  else
    string_or_date_object
  end
end
year(target_year) click to toggle source
# File lib/rock_books/filters/journal_entry_filters.rb, line 29
def year(target_year)
  ->(entry) { entry.date.year == target_year }
end