-
-
Save rupl/5464755 to your computer and use it in GitHub Desktop.
Word counter for writing articles. Allows you to count lines of code at a different rate than regular words.
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 'rubygems' | |
require 'rdiscount' | |
require 'nokogiri' | |
words = 0 | |
limit = 2700 | |
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 | |
if words < limit | |
puts "You need to add #{limit - words} words" | |
else | |
puts "You need to cut #{words - limit} words" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment