From 44dee2b4f3632433837f2465ce105c27e9ceff8c Mon Sep 17 00:00:00 2001 From: Simon Parri Date: Fri, 1 Feb 2019 16:18:39 -0600 Subject: Neaten up code with function --- spelling-rbee | 31 ++++++++++++++++--------------- 1 file 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 -- cgit v1.2.3