Skip to content

Instantly share code, notes, and snippets.

@lastab
Last active June 7, 2017 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lastab/37ea0c8fc89cfbb4090a71ebb516cf14 to your computer and use it in GitHub Desktop.
Save lastab/37ea0c8fc89cfbb4090a71ebb516cf14 to your computer and use it in GitHub Desktop.
# file type PDF
# word is in odd page and meaning is in even page
require 'rubygems'
require "pdf/reader"
reader = PDF::Reader.new("Vocabulary Flash Cards1.pdf")
word_count = reader.page_count / 2
random_word_index = rand(2..word_count) * 2 - 1
# 2.. is used because first 4 pages contains conver and table of contents
meaning_index = random_word_index + 1
word = reader.pages[random_word_index]
meaning = reader.pages[meaning_index]
word_meaning = "#{word}\n #{meaning}"
puts word_meaning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment