Class: JekyllRecker::Graphs::WordCount
- Inherits:
-
Object
- Object
- JekyllRecker::Graphs::WordCount
- Defined in:
- lib/jekyll_recker/graphs.rb
Overview
Word Count Graph
Instance Method Summary collapse
- #graphs_join(path) ⇒ Object
-
#initialize(posts, graphs_dir) ⇒ WordCount
constructor
A new instance of WordCount.
- #labels ⇒ Object
-
#number_of_words(input) ⇒ Object
TODO: copied from jekyll.
- #title ⇒ Object
- #write ⇒ Object
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 |
#labels ⇒ Object
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 |
#title ⇒ Object
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 |
#write ⇒ Object
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 |