Created
November 6, 2016 19:49
-
-
Save sortega/f4434712a4c499474ad0727bf275928f to your computer and use it in GitHub Desktop.
A spelling tutor script for OSX (you need to have a working `say` command)
This file contains 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/env ruby | |
require 'optparse' | |
SPELLINGS = Hash.new { |hash, key| key } | |
SPELLINGS['n'] = 'an' | |
SPELLINGS['z'] = 'zet' | |
command = :none | |
parser = OptionParser.new do |opts| | |
opts.banner = "Usage: spell_tutor.rb [--spelling|--dictation]" | |
opts.on('--spelling', 'Practice spelling out words') do | |
command = :spelling | |
end | |
opts.on('--dictation', 'Practice letter-by-letter dictation') do | |
command = :dictation | |
end | |
end | |
class Dict | |
DICT_PATH = '/usr/share/dict/words' | |
def initialize | |
@entries = [] | |
File.foreach(DICT_PATH) do |line| | |
@entries << line | |
end | |
end | |
def pick_word | |
begin | |
pick = @entries.sample | |
end until pick.size <= 8 | |
pick.downcase | |
end | |
end | |
def practice_spelling | |
puts 'Spelling!' | |
dict = Dict.new | |
loop do | |
word = dict.pick_word | |
puts "Spell: #{word}" | |
press_enter_to 'get a sample spelling' | |
spell word | |
end | |
end | |
def practice_dictation | |
puts 'Dictation!' | |
dict = Dict.new | |
loop do | |
word = dict.pick_word | |
press_enter_to 'listen to the next word' | |
spell word | |
press_enter_to 'reveal the word' | |
puts word | |
puts | |
end | |
end | |
def spell(word) | |
text = word.scan(/\w/).map do |c| | |
SPELLINGS[c] | |
end.join(' . ') | |
%x(say -r 160 #{text}) | |
end | |
def press_enter_to(action) | |
puts "(press enter to #{action})" | |
readline | |
end | |
parser.parse! | |
case command | |
when :spelling | |
practice_spelling | |
when :dictation | |
practice_dictation | |
else | |
puts parser | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment