Module: RockBooks::JournalEntryFilters
- Included in:
- CommandLineInterface
- Defined in:
- lib/rock_books/filters/journal_entry_filters.rb
Class Method Summary collapse
- .account_code(account_code) ⇒ Object
- .all(*filters) ⇒ Object
- .any(*filters) ⇒ Object
- .date_in_range(start_date, end_date) ⇒ Object
- .date_on_or_after(date) ⇒ Object
- .date_on_or_before(date) ⇒ Object
- .day(target_year, target_month, target_day) ⇒ Object
- .filter(entries, entry_filter) ⇒ Object
- .month(target_year, target_month) ⇒ Object
- .none(*filters) ⇒ Object
- .null_filter ⇒ Object
-
.to_date(string_or_date_object) ⇒ Object
Dates can be provided as a Ruby Date object, or as a string that will be converted to date (yyyy-mm-dd).
- .year(target_year) ⇒ Object
Class Method Details
.account_code(account_code) ⇒ Object
48 49 50 51 52 |
# 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) ⇒ Object
74 75 76 |
# File 'lib/rock_books/filters/journal_entry_filters.rb', line 74 def all(*filters) ->(entry) { filters.all? { |filter| filter.(entry) } } end |
.any(*filters) ⇒ Object
79 80 81 |
# 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) ⇒ Object
67 68 69 70 71 |
# 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) ⇒ Object
55 56 57 58 |
# 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) ⇒ Object
61 62 63 64 |
# 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) ⇒ Object
41 42 43 44 45 |
# 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) ⇒ Object
9 10 11 |
# 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) ⇒ Object
34 35 36 37 38 |
# 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) ⇒ Object
84 85 86 |
# File 'lib/rock_books/filters/journal_entry_filters.rb', line 84 def none(*filters) ->(entry) { filters.none? { |filter| filter.(entry) } } end |
.null_filter ⇒ Object
24 25 26 |
# File 'lib/rock_books/filters/journal_entry_filters.rb', line 24 def null_filter ->(entry) { true } end |
.to_date(string_or_date_object) ⇒ Object
Dates can be provided as a Ruby Date object, or as a string that will be converted to date (yyyy-mm-dd).
15 16 17 18 19 20 21 |
# 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) ⇒ Object
29 30 31 |
# File 'lib/rock_books/filters/journal_entry_filters.rb', line 29 def year(target_year) ->(entry) { entry.date.year == target_year } end |