Class: Rollin::Blog

Inherits:
Object
  • Object
show all
Defined in:
lib/rollin/blog.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Blog

Returns a new instance of Blog.



2
3
4
# File 'lib/rollin/blog.rb', line 2

def initialize(options = {})
  @articles_folder = options[:articles_folder] || 'articles'
end

Instance Method Details

#annual_archiveObject



33
34
35
36
37
# File 'lib/rollin/blog.rb', line 33

def annual_archive
  monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
    Rollin::YearArchive.new(year, monthly_archive.select { |aMonth| aMonth.year == year })
  end
end

#article(search = {}) ⇒ Object



6
7
8
# File 'lib/rollin/blog.rb', line 6

def article(search = {})
  unfiltered_articles.find { |article| article.matches?(search) }
end

#articles(search = {}) ⇒ Object



10
11
12
# File 'lib/rollin/blog.rb', line 10

def articles(search = {})
  unfiltered_articles.select { |article| article.matches?(search) }
end

#metatagsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rollin/blog.rb', line 18

def metatags
  metatag_labels = unfiltered_articles.map do |article|
    article.metatags.keys
  end.flatten.uniq

  metatag_labels.map do |metatag_label|
    values = unfiltered_articles.select { |article| article.metatags.has_key?(metatag_label) }.map do |article|
      article.metatags[metatag_label]
    end.flatten.uniq.map do |metatag_content|
      Rollin::MetatagValue.new(metatag_content, articles(metatag_label => metatag_content))
    end
    Rollin::MetatagKey.new(metatag_label, values)
  end
end

#monthly_archiveObject



39
40
41
42
43
44
45
46
# File 'lib/rollin/blog.rb', line 39

def monthly_archive
  articles.map { |article| [article.year, article.month] }.uniq.map do |year_and_month|
    year = year_and_month[0]
    month = year_and_month[1]
    articles_for_month = articles.select { |anArticle| anArticle.year == year && anArticle.month == month }
    Rollin::MonthArchive.new(year, month, articles_for_month)
  end
end

#unfiltered_articlesObject



14
15
16
# File 'lib/rollin/blog.rb', line 14

def unfiltered_articles
  read_articles.reverse
end