Created
October 16, 2010 15:57
-
-
Save chriseppstein/629946 to your computer and use it in GitHub Desktop.
counts words for an article I'm writing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rdiscount' | |
require 'nokogiri' | |
words = 0 | |
content = $stdin.read | |
html = RDiscount.new(content).to_html | |
doc = Nokogiri::HTML(html) | |
codes = doc.css("pre code") | |
codes.each do |code| | |
words += code.inner_html.split("\n").size * 15 | |
code.parent.remove | |
end | |
words += doc.inner_text.split(/\s+/).size | |
puts words | |
puts "You need to cut #{words - 2700} words" |
Yes thanks a ton for this! I got a minor error when I ran it too.
wc.rb:2:in
require': no such file to load -- rdiscount (LoadError)`
I'm not a ruby dev so maybe it's obvious but I had to add the following line above the other required gems and now it works perfect:
require 'rubygems'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the gist! Just a small note: only works for me if I use
content = ARGF.read
instead ofcontent = $stdin.read