diff options
author | Simon Parri <simonparri@ganzeria.com> | 2020-03-30 14:45:34 -0500 |
---|---|---|
committer | Simon Parri <simonparri@ganzeria.com> | 2020-03-30 14:45:34 -0500 |
commit | 7c02c63cfcd476e60b9c91b64ddd17f8051aaf59 (patch) | |
tree | f851c9ebfe0daa13fc7b3ca9689a480818e87c98 | |
parent | 0686901f6e1edd872a2a1b3562031ab4f0eccfb7 (diff) | |
download | spelling-rbee-7c02c63cfcd476e60b9c91b64ddd17f8051aaf59.tar.gz spelling-rbee-7c02c63cfcd476e60b9c91b64ddd17f8051aaf59.zip |
neaten up code
-rwxr-xr-x | spelling-rbee | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/spelling-rbee b/spelling-rbee index bff49a6..1c79af0 100755 --- a/spelling-rbee +++ b/spelling-rbee @@ -11,14 +11,6 @@ def say(it,speed=100) system "espeak -s #{speed} '#{it}'" end -def ckopt(word, result) - case result - when ":r" then say word - when ":imacheaterandknowit" then puts word - when ":q" then $exit = true - end -end - def ckword(word,result) if result == word return [word, "correct", result] @@ -34,34 +26,46 @@ def read(file) end def repl(words) - correct = [] - words.each {|word| + results = [] + words.each do |word| say word result = get - until result[0] != ":" - ckopt(word,result) - if $exit - return $exit - end - result = get + # while result[0] == ":" + # ckopt(word,result) + # if $exit + # return $exit + # end + # result = get + # end + case result + when ":r" + redo + when ":imacheaterandknowit" + puts word + redo + when ":q" + $exit = true end - correct.push ckword(word,result) - } - return correct + break if $exit + results.push ckword(word,result) + end + return results end -def rcorrect(words) - correct = [] +def results(words) + results = [] words.each {|word| - correct.push(word[0] + ": " + word[1] + ": " + word[2]) + results.push(word[0] + ": " + word[1] + ": " + word[2]) } return correct end -def run(file) +def run(file = (ARGV[0] || "http://zoar.cx/~simon/21k/words.txt")) + $exit = false words = read file correct = repl words - puts rcorrect correct unless correct == true + return true if $exit + puts results results end -run (ARGV[0] || "http://zoar.cx/~simon/21k/words.txt") +run |