Class: JekyllRecker::Graphs::WordCount
- Inherits:
-
Object
- Object
- JekyllRecker::Graphs::WordCount
- Includes:
- Base
- Defined in:
- lib/jekyll_recker/graphs.rb
Overview
Word Count Graph
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
-
#initialize(site) ⇒ WordCount
constructor
A new instance of WordCount.
- #labels ⇒ Object
- #posts ⇒ Object
- #title ⇒ Object
- #word_counts ⇒ Object
- #write ⇒ Object
Methods included from Base
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
#labels ⇒ Object
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 |
#posts ⇒ Object
30 31 32 |
# File 'lib/jekyll_recker/graphs.rb', line 30 def posts site.entries[0..6].reverse end |
#title ⇒ Object
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_counts ⇒ Object
34 35 36 |
# File 'lib/jekyll_recker/graphs.rb', line 34 def word_counts site.word_counts[0..6].reverse end |
#write ⇒ Object
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 |