class JekyllRecker::Graphs::WordCount

Word Count Graph

Public Class Methods

new(site) click to toggle source
# File lib/jekyll_recker/graphs.rb, line 25
def initialize(site)
  @site = site
  @graphs_dir = site.graphs_dir
end

Public Instance Methods

labels() click to toggle source
# File lib/jekyll_recker/graphs.rb, line 45
def labels
  Hash[posts.each_with_index.map { |p, i| [i, p.date.strftime('%a')] }]
end
posts() click to toggle source
# File lib/jekyll_recker/graphs.rb, line 30
def posts
  site.entries[0..6].reverse
end
title() click to toggle source
# File lib/jekyll_recker/graphs.rb, line 38
def title
  format = '%m/%d/%y'
  first = posts.first.date.strftime(format)
  last = posts.last.date.strftime(format)
  "Word Count: #{first} - #{last}"
end
word_counts() click to toggle source
# File lib/jekyll_recker/graphs.rb, line 34
def word_counts
  site.word_counts[0..6].reverse
end
write() click to toggle source
# File lib/jekyll_recker/graphs.rb, line 49
def write
  g = ::Gruff::Line.new('800x600')
  g.theme = Gruff::Themes::PASTEL
  g.hide_legend = true
  g.labels = labels
  g.data :words, word_counts
  g.title = title
  g.x_axis_label = 'Day'
  g.y_axis_label = 'Word Count'
  g.minimum_value = 0
  g.write(graphs_join('words.png'))
end