From 12d99f0720a688ec68108daad9d686ed3d1276b0 Mon Sep 17 00:00:00 2001 From: muflax Date: Wed, 28 Nov 2012 02:56:52 +0100 Subject: [PATCH] complete word count --- commands/wc.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/commands/wc.rb b/commands/wc.rb index f781ed4..ec1b092 100644 --- a/commands/wc.rb +++ b/commands/wc.rb @@ -18,15 +18,27 @@ module Nanoc::CLI::Commands i.reps.any? {|r| r.name == :wordcount} end + total = total_practice = 0 logs.each do |log| - content = log.rep_named(:wordcount).compiled_content - stripped = strip content.dup.force_encoding("utf-8") - words = stripped.scan(/( \S+ )/x) - puts "#{log.identifier} -> #{words.size}" + practice = words_in_content log, :wordcount + all_words = words_in_content log, :default + + total += all_words + total_practice += practice + + puts "#{log.identifier} -> #{practice} / #{all_words}" end + puts "total: #{total_practice} / #{total}" end end + def words_in_content log, rep + content = log.rep_named(rep).compiled_content + stripped = strip content.dup.force_encoding("utf-8") + words = stripped.scan(/( \S+ )/x) + words.size + end + def strip content Sanitize.clean(content, :remove_contents => %w{blockquote})