Last active
June 7, 2017 16:31
-
-
Save lastab/37ea0c8fc89cfbb4090a71ebb516cf14 to your computer and use it in GitHub Desktop.
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
# 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