Class: Cloudpress::Archive

Inherits:
Object
  • Object
show all
Defined in:
app/models/cloudpress/archive.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#rangeObject (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

.allObject



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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

#monthsObject



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

#postsObject



45
46
47
# File 'app/models/cloudpress/archive.rb', line 45

def posts
  @posts ||= Cloudpress::Post.published.between(@range)
end

#yearObject



37
38
39
# File 'app/models/cloudpress/archive.rb', line 37

def year
  range.first.year
end