Class: Dimples::Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/dimples/archive.rb

Overview

A collection of posts, organised by date.

Instance Method Summary collapse

Constructor Details

#initializeArchive

Returns a new instance of Archive.



6
7
8
# File 'lib/dimples/archive.rb', line 6

def initialize
  @years = {}
end

Instance Method Details

#add_post(post) ⇒ Object



10
11
12
13
14
# File 'lib/dimples/archive.rb', line 10

def add_post(post)
  year(post.year)[:posts] << post
  month(post.year, post.month)[:posts] << post
  day(post.year, post.month, post.day)[:posts] << post
end

#day_posts(year, month, day) ⇒ Object



46
47
48
# File 'lib/dimples/archive.rb', line 46

def day_posts(year, month, day)
  day(year, month, day)[:posts]
end

#days(year, month) ⇒ Object



24
25
26
# File 'lib/dimples/archive.rb', line 24

def days(year, month)
  month(year, month)[:days].keys
end

#month_posts(year, month) ⇒ Object



42
43
44
# File 'lib/dimples/archive.rb', line 42

def month_posts(year, month)
  month(year, month)[:posts]
end

#months(year) ⇒ Object



20
21
22
# File 'lib/dimples/archive.rb', line 20

def months(year)
  year(year)[:months].keys
end

#posts_for_date(year, month = nil, day = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/dimples/archive.rb', line 28

def posts_for_date(year, month = nil, day = nil)
  if day
    day_posts(year, month, day)
  elsif month
    month_posts(year, month)
  else
    year_posts(year)
  end
end

#year_posts(year) ⇒ Object



38
39
40
# File 'lib/dimples/archive.rb', line 38

def year_posts(year)
  year(year)[:posts]
end

#yearsObject



16
17
18
# File 'lib/dimples/archive.rb', line 16

def years
  @years.keys
end