Class: JekyllRecker::Generators::Stats

Inherits:
Jekyll::Generator
  • Object
show all
Includes:
Date, Logging, Math
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.



12
13
14
# File 'lib/jekyll_recker/generators.rb', line 12

def site
  @site
end

Instance Method Details

#generate(site) ⇒ Object



14
15
16
17
18
# File 'lib/jekyll_recker/generators.rb', line 14

def generate(site)
  @site = Site.new(site)
  info 'calculating statistics'
  site.data['stats'] = stats
end

#statsObject



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

def stats
  @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