Created
October 5, 2013 02:56
-
-
Save l3thal/6836116 to your computer and use it in GitHub Desktop.
docx unique word count
This file contains hidden or 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/ruby | |
require 'zip' | |
require 'nokogiri' | |
class Docx | |
def self.word_count(file, zip=Zip::ZipFile.open(file)) | |
Nokogiri::XML.parse(zip.find_entry("word/document.xml").get_input_stream).text.split(" ").uniq.length | |
end | |
end | |
puts Docx.word_count("sample.docx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have to change the first line,
Thanks
📋 Reference