Class: PagesCore::ArchiveFinder
- Inherits:
-
Object
- Object
- PagesCore::ArchiveFinder
- Defined in:
- lib/pages_core/archive_finder.rb
Instance Method Summary collapse
- #by_year(year) ⇒ Object
- #by_year_and_month(year, month) ⇒ Object
-
#initialize(relation, options = {}) ⇒ ArchiveFinder
constructor
A new instance of ArchiveFinder.
- #latest_year ⇒ Object
- #latest_year_and_month ⇒ Object
- #months_in_year(year) ⇒ Object
- #months_in_year_with_count(year) ⇒ Object
- #timestamp_attribute ⇒ Object
- #years ⇒ Object
- #years_with_count ⇒ Object
Constructor Details
#initialize(relation, options = {}) ⇒ ArchiveFinder
Returns a new instance of ArchiveFinder.
3 4 5 6 |
# File 'lib/pages_core/archive_finder.rb', line 3 def initialize(relation, = {}) @relation = relation @options = end |
Instance Method Details
#by_year(year) ⇒ Object
8 9 10 |
# File 'lib/pages_core/archive_finder.rb', line 8 def by_year(year) filter_by_time(range_for_year(year)) end |
#by_year_and_month(year, month) ⇒ Object
12 13 14 |
# File 'lib/pages_core/archive_finder.rb', line 12 def by_year_and_month(year, month) filter_by_time(range_for_year_and_month(year, month)) end |
#latest_year ⇒ Object
16 17 18 |
# File 'lib/pages_core/archive_finder.rb', line 16 def latest_year latest_year_and_month&.first end |
#latest_year_and_month ⇒ Object
20 21 22 23 24 25 |
# File 'lib/pages_core/archive_finder.rb', line 20 def latest_year_and_month ordered_relation.first.try do |record| [record[].year, record[].month] end end |
#months_in_year(year) ⇒ Object
27 28 29 |
# File 'lib/pages_core/archive_finder.rb', line 27 def months_in_year(year) select_months(by_year(year)).map(&:to_i).sort end |
#months_in_year_with_count(year) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/pages_core/archive_finder.rb', line 31 def months_in_year_with_count(year) group_by_month(by_year(year)) .count .to_a .sort_by(&:first) end |
#timestamp_attribute ⇒ Object
38 39 40 |
# File 'lib/pages_core/archive_finder.rb', line 38 def @options[:timestamp] || :created_at end |
#years ⇒ Object
42 43 44 |
# File 'lib/pages_core/archive_finder.rb', line 42 def years select_years(@relation).map(&:to_i).sort end |
#years_with_count ⇒ Object
46 47 48 |
# File 'lib/pages_core/archive_finder.rb', line 46 def years_with_count years.map { |year| [year, by_year(year).count] } end |