summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xspelling-rbee93
1 files changed, 46 insertions, 47 deletions
diff --git a/spelling-rbee b/spelling-rbee
index da2905a..cbd30d2 100755
--- a/spelling-rbee
+++ b/spelling-rbee
@@ -1,65 +1,64 @@
#!/usr/bin/ruby
-FILE = ARGV[0] || "http://zoar.cx/~simon/21k/words.txt"
require "open-uri"
-words = []
-correct = []
+
+def say(it,speed=100)
+system "espeak -s #{speed} '#{it}'"
+end
def ckopt(word, result)
case result
- when "_r" then system "espeak -s 100 #{word}"
- when "_imacheaterandknowit" then puts word
+ when ":r" then say word
+ when ":imacheaterandknowit" then puts word
+ when ":q" then $exit = true
end
end
-open FILE do |f|
- f.each do |line|
- words.push line.chomp
+def ckword(word,result)
+ if result == word
+ return [word, "correct", result]
+ else
+ return [word, "wrong", result]
end
end
-=begin
-open FILE do |f|
- words = f.readlines.map(&:chomp)
-end
-=end
-
-=begin
-file = open FILE
-neof = true
-while neof
- line = file.gets
- if line == nil
- neof = false
- break
- end
- if line
- line.chomp!
- words.push line
+def read(file)
+ open file do |f|
+ return f.readlines.map(&:chomp)
end
end
-puts "words: %d" % words.length
-=end
-words.each {|word|
- system "espeak -s 100 '#{word}'"
- print "spell: "
- result = $stdin.gets.chomp!
- if result.start_with? "_"
- ckopt(word,result)
- while result.start_with? "_"
+def repl(words)
+ correct = []
+ words.each {|word|
+ print "spell: "
+ say word
+ result = $stdin.gets.chomp!
+ until result[0] != ":"
+ ckopt(word,result)
+ if $exit
+ return $exit
+ end
print "spell: "
result = $stdin.gets.chomp!
- ckopt(word,result)
end
- end
- if result == word
- correct.push [word, "correct", result]
- else
- correct.push [word, "wrong", result]
- end
-}
-puts
-correct.each {|word|
- puts word[0] + ": " + word[1] + ": " + word[2]
-}
+ correct.push ckword(word,result)
+ }
+ return correct
+end
+
+def rcorrect(words)
+ correct = []
+ words.each {|word|
+ correct.push(word[0] + ": " + word[1] + ": " + word[2])
+ }
+ return correct
+end
+
+def run(file)
+ words = read file
+ correct = repl words
+ puts rcorrect correct unless correct == true
+end
+
+run (ARGV[0] || "http://zoar.cx/~simon/21k/words.txt")