summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Parri <simonparri@ganzeria.com>2019-02-01 16:18:39 -0600
committerSimon Parri <simonparri@ganzeria.com>2019-02-01 16:18:39 -0600
commit44dee2b4f3632433837f2465ce105c27e9ceff8c (patch)
treee2a3215bf4e19ee9f7608c634bb6831083bd6ef2
parent218c1c0d081c7995a9bb9ae2e2a563e831cf512b (diff)
downloadspelling-rbee-44dee2b4f3632433837f2465ce105c27e9ceff8c.tar.gz
spelling-rbee-44dee2b4f3632433837f2465ce105c27e9ceff8c.zip
Neaten up code with function
-rwxr-xr-xspelling-rbee31
1 files changed, 16 insertions, 15 deletions
diff --git a/spelling-rbee b/spelling-rbee
index feedc82..da2905a 100755
--- a/spelling-rbee
+++ b/spelling-rbee
@@ -5,6 +5,13 @@ require "open-uri"
words = []
correct = []
+def ckopt(word, result)
+ case result
+ when "_r" then system "espeak -s 100 #{word}"
+ when "_imacheaterandknowit" then puts word
+ end
+end
+
open FILE do |f|
f.each do |line|
words.push line.chomp
@@ -37,25 +44,19 @@ puts "words: %d" % words.length
words.each {|word|
system "espeak -s 100 '#{word}'"
print "spell: "
- $result = $stdin.gets.chomp!
- if $result.start_with? "_"
- case $result
- when "_r" then system "espeak -s 100 #{word}"
- when "_imacheaterandknowit" then puts word
- end
- while $result.start_with? "_"
+ result = $stdin.gets.chomp!
+ if result.start_with? "_"
+ ckopt(word,result)
+ while result.start_with? "_"
print "spell: "
- $result = $stdin.gets.chomp!
- case $result
- when "_r" then system "espeak -s 100 #{word}"
- when "_imacheaterandknowit" then puts word
- end
+ result = $stdin.gets.chomp!
+ ckopt(word,result)
end
end
- if $result == word
- correct.push [word, "correct", $result]
+ if result == word
+ correct.push [word, "correct", result]
else
- correct.push [word, "wrong", $result]
+ correct.push [word, "wrong", result]
end
}
puts