Skip to content

Instantly share code, notes, and snippets.

@l3thal
Created October 5, 2013 02:56
Show Gist options
  • Save l3thal/6836116 to your computer and use it in GitHub Desktop.
Save l3thal/6836116 to your computer and use it in GitHub Desktop.
docx unique word count
#!/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")
@seyyah
Copy link

seyyah commented Jun 18, 2018

We have to change the first line,

require 'zip/zip'

Thanks

📋 Reference

  1. adjust/pgbundle#23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment