Class: JekyllRecker::Generators::Stats

Inherits:
Jekyll::Generator
  • Object
show all
Includes:
Base
Defined in:
lib/jekyll_recker/generators.rb

Overview

Stats Generator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Math

#average, #occurences, #total

Methods included from Logging

included, #info, #logger

Methods included from Date

#calculate_streaks, #slice_by_consecutive, #time_to_date

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



17
18
19
# File 'lib/jekyll_recker/generators.rb', line 17

def site
  @site
end

Instance Method Details

#generate(site) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll_recker/generators.rb', line 19

def generate(site)
  @site = Site.new(site)
  generate_stats!
  if @site.production?
    info 'production detected. skipping graphs'
  else
    info 'generating graphs'
    Graphs.generate_graphs(@site)
  end
end

#generate_stats!Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/jekyll_recker/generators.rb', line 30

def generate_stats!
  info 'calculating statistics'
  site.data['stats'] = {
    'total_words' => total(site.word_counts),
    'average_words' => average(site.word_counts),
    'total_posts' => site.entries.size,
    'consecutive_posts' => calculate_streaks(site.dates).first['days'],
    'swears' => calculate_swears
  }
end