Skip to content

Instantly share code, notes, and snippets.

@Evshved
Created February 20, 2018 00:39
Show Gist options
  • Select an option

  • Save Evshved/608da68f4f83e2f8bab33ae1b0be1050 to your computer and use it in GitHub Desktop.

Select an option

Save Evshved/608da68f4f83e2f8bab33ae1b0be1050 to your computer and use it in GitHub Desktop.
require 'pdf-reader'
require 'pry'
pdf = PDF::Reader.new('RUM_CH6_excerpt.pdf')
words = pdf.pages[1].text
words.gsub!(/[!@%&."]/,'')
words = words.split(' ')
dictionary = words.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
sample = dictionary.sort_by { |k,v| v}.reverse
File.open('test.txt', 'w') { |file| file.write(sample) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment