Class: JekyllRecker::Graphs::WordCount

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/jekyll_recker/graphs.rb

Overview

Word Count Graph

Instance Attribute Summary

Attributes included from Base

#site

Instance Method Summary collapse

Methods included from Base

#graphs_join

Constructor Details

#initialize(site) ⇒ WordCount

Returns a new instance of WordCount.



25
26
27
28
# File 'lib/jekyll_recker/graphs.rb', line 25

def initialize(site)
  @site = site
  @graphs_dir = site.graphs_dir
end

Instance Method Details

#labelsObject



45
46
47
# File 'lib/jekyll_recker/graphs.rb', line 45

def labels
  Hash[posts.each_with_index.map { |p, i| [i, p.date.strftime('%a')] }]
end

#postsObject



30
31
32
# File 'lib/jekyll_recker/graphs.rb', line 30

def posts
  site.entries[0..6].reverse
end

#titleObject



38
39
40
41
42
43
# 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_countsObject



34
35
36
# File 'lib/jekyll_recker/graphs.rb', line 34

def word_counts
  site.word_counts[0..6].reverse
end

#writeObject



49
50
51
52
53
54
55
56
57
58
59
60
# 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