Class: Reading::Filter
Overview
Filters Items based on given criteria.
Class Method Summary collapse
-
.by(items:, no_sort: false, **criteria) ⇒ Array<Item>
Filters Items based on given criteria, and returns them sorted by last end date or (where there is none) status, where :planned Items are placed last, and :in_progress just before those.
Class Method Details
.by(items:, no_sort: false, **criteria) ⇒ Array<Item>
Filters Items based on given criteria, and returns them sorted by last end date or (where there is none) status, where :planned Items are placed last, and :in_progress just before those.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/reading/filter.rb', line 13 def by(items:, no_sort: false, **criteria) validate_criteria(**criteria) filtered = criteria.each.with_object(items.dup) { |(criterion, arg), filtered_items| send("#{CRITERIA_PREFIX}#{criterion}#{CRITERIA_SUFFIX}", filtered_items, arg) } return filtered if no_sort filtered.sort_by { |item| if item.done? item.last_end_date.strftime("%Y-%m-%d") else item.status.to_s end } end |