Module: JekyllRecker::Generators::Stats Abstract
- Includes:
- Jekyll::Filters, Mixins::Logging
- Defined in:
- lib/jekyll_recker/generators.rb
Overview
This module is abstract.
Stats Module
Functions for stats generators.
Instance Method Summary collapse
-
#average(numlist) ⇒ Numeric
Calculates the average of a list of numbers.
- #crunch ⇒ Object
- #entries ⇒ Object
- #generate(site) ⇒ Object
- #key ⇒ Object
-
#total(numlist) ⇒ Numeric
Calculates the total of a list of numbers.
Methods included from Mixins::Logging
Instance Method Details
#average(numlist) ⇒ Numeric
Calculates the average of a list of numbers.
75 76 77 78 |
# File 'lib/jekyll_recker/generators.rb', line 75 def average(numlist) calc = numlist.inject { |sum, el| sum + el }.to_f / numlist.size calc.round end |
#crunch ⇒ Object
67 68 69 |
# File 'lib/jekyll_recker/generators.rb', line 67 def crunch raise NotImplementedError, '#crunch not implemented!' end |
#entries ⇒ Object
88 89 90 |
# File 'lib/jekyll_recker/generators.rb', line 88 def entries @site.posts.docs.select(&:published?) end |
#generate(site) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/jekyll_recker/generators.rb', line 60 def generate(site) @site = site logger.info "crunching stats.#{key}" @site.data['stats'] ||= {} @site.data['stats'][key] = crunch end |
#key ⇒ Object
56 57 58 |
# File 'lib/jekyll_recker/generators.rb', line 56 def key self.class.const_get(:KEY) end |
#total(numlist) ⇒ Numeric
Calculates the total of a list of numbers.
84 85 86 |
# File 'lib/jekyll_recker/generators.rb', line 84 def total(numlist) numlist.inject(0) { |sum, x| sum + x } end |