Module: JekyllRecker::Generators::Stats Abstract

Includes:
Jekyll::Filters, Mixins::Logging
Included in:
Memory, PostCount, Streaks, Swears, Words
Defined in:
lib/jekyll_recker/generators.rb

Overview

This module is abstract.

Stats Module

Functions for stats generators.

Instance Method Summary collapse

Methods included from Mixins::Logging

#logger

Instance Method Details

#average(numlist) ⇒ Numeric

Calculates the average of a list of numbers.

Parameters:

  • numlist (Array<Numeric>)

    list of numbers to be averaged.

Returns:

  • (Numeric)

    rounded, calculated average of numlist.



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

#crunchObject

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/jekyll_recker/generators.rb', line 67

def crunch
  raise NotImplementedError, '#crunch not implemented!'
end

#entriesObject



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

#keyObject



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.

Parameters:

  • numlist (Array<Numeric>)

    list of numbers to be totaled.

Returns:

  • (Numeric)

    calculated total of numlist.



84
85
86
# File 'lib/jekyll_recker/generators.rb', line 84

def total(numlist)
  numlist.inject(0) { |sum, x| sum + x }
end