Class: Cloudpress::Archive
- Inherits:
-
Object
- Object
- Cloudpress::Archive
- Defined in:
- app/models/cloudpress/archive.rb
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(range) ⇒ Archive
constructor
A new instance of Archive.
- #months ⇒ Object
- #posts ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(range) ⇒ Archive
Returns a new instance of Archive.
33 34 35 |
# File 'app/models/cloudpress/archive.rb', line 33 def initialize(range) @range = range end |
Instance Attribute Details
#range ⇒ Object (readonly)
Returns the value of attribute range.
31 32 33 |
# File 'app/models/cloudpress/archive.rb', line 31 def range @range end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'app/models/cloudpress/archive.rb', line 5 def all wrap(Cloudpress::Post.unscoped.published.group_by_month(:publish_date).count.keys.group_by {|x| x.year}) end |
.find(date) ⇒ Object
14 15 16 17 |
# File 'app/models/cloudpress/archive.rb', line 14 def find(date) raise ArgumentError unless date.respond_to?(:year) new(date_range(date.beginning_of_month..date.end_of_month)) end |
.year(date) ⇒ Object
9 10 11 12 |
# File 'app/models/cloudpress/archive.rb', line 9 def year(date) raise ArgumentError unless date.respond_to?(:year) new(date_range(date.beginning_of_year..date.end_of_year)) end |
Instance Method Details
#months ⇒ Object
41 42 43 |
# File 'app/models/cloudpress/archive.rb', line 41 def months @months ||= (range.first.to_date..range.last.to_date).map {|x| x.beginning_of_month}.uniq end |
#posts ⇒ Object
45 46 47 |
# File 'app/models/cloudpress/archive.rb', line 45 def posts @posts ||= Cloudpress::Post.published.between(@range) end |
#year ⇒ Object
37 38 39 |
# File 'app/models/cloudpress/archive.rb', line 37 def year range.first.year end |