Class: JekyllRecker::Graphs::WordCount

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

Overview

Word Count Graph

Instance Method Summary collapse

Constructor Details

#initialize(posts, graphs_dir) ⇒ WordCount

Returns a new instance of WordCount.



15
16
17
18
# File 'lib/jekyll_recker/graphs.rb', line 15

def initialize(posts, graphs_dir)
  @posts = posts[0..6].reverse
  @graphs_dir = graphs_dir
end

Instance Method Details

#graphs_join(path) ⇒ Object



20
21
22
# File 'lib/jekyll_recker/graphs.rb', line 20

def graphs_join(path)
  File.join Bundler.root, @graphs_dir, path
end

#labelsObject



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

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

#number_of_words(input) ⇒ Object

TODO: copied from jekyll



36
37
38
# File 'lib/jekyll_recker/graphs.rb', line 36

def number_of_words(input)
  input.split.length
end

#titleObject



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

def title
  format = '%m/%d/%y'
  first = @posts.first.date.strftime(format)
  last = @posts.last.date.strftime(format)
  "Word Count: #{first} - #{last}"
end

#writeObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jekyll_recker/graphs.rb', line 40

def write
  g = Gruff::Line.new('800x600')
  g.theme = Gruff::Themes::PASTEL
  g.hide_legend = true
  g.labels = labels
  g.data :words, @posts.collect(&:content).map { |c| number_of_words(c) }
  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