Class: Feedback
Class Method Summary collapse
- .get_boolean(question) ⇒ Object
- .get_choice(question, choice) ⇒ Object
- .get_custom(question, regexp) ⇒ Object
- .get_float(question) ⇒ Object
- .gets ⇒ Object
Instance Method Summary collapse
-
#gets ⇒ Object
No reading from the command line thank you very much!.
Class Method Details
.get_boolean(question) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coderunner/feedback.rb', line 26 def Feedback.get_boolean(question) puts question cont = true while cont puts "---Please enter y or n" answer = gets if answer =~ /^n$/i cont = false bool = false elsif answer =~ /^y$/i cont = false bool = true else puts "Incorrect selection: #{answer.inspect}" end end return bool end |
.get_choice(question, choice) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/coderunner/feedback.rb', line 60 def Feedback.get_choice(question, choice) case choice when Hash puts question cont = true old_choice = choice; choice = {} old_choice.each do |key,value| choice[key.to_s] = old_choice[key] end while cont puts "Please select your choice (case sensitive)" choice.each do |key,value| puts key.to_s + ": " + value.to_s end answer = gets.chomp if choice[answer] cont = false answer = choice[answer] else puts "Incorrect Selection: #{answer.inspect} - Please try again" end end when Array hash = {} choice.each_with_index{|choice,i| hash[i] = choice} answer = self.get_choice(question, hash) end return answer end |
.get_custom(question, regexp) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/coderunner/feedback.rb', line 10 def Feedback.get_custom(question, regexp) #NB regex is submitted as a string puts question cont = true while cont puts "---Please enter an answer of the form " + regexp answer = gets.to_s if answer =~ Regexp.new(regexp) cont = false else puts "Incorrect form" end end return answer.chomp end |
.get_float(question) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/coderunner/feedback.rb', line 45 def Feedback.get_float(question) puts question cont = true while cont puts "---Please enter an answer of the form ^-?\\d[.e-\\d]*$" answer = gets if answer =~ /^-?\d[\d\.e-]*$/ cont = false else puts "Incorrect selection: #{answer.inspect}" end end return answer.to_f end |
.gets ⇒ Object
6 7 8 |
# File 'lib/coderunner/feedback.rb', line 6 def self.gets $stdin.gets end |
Instance Method Details
#gets ⇒ Object
No reading from the command line thank you very much!
3 4 5 |
# File 'lib/coderunner/feedback.rb', line 3 def gets #No reading from the command line thank you very much! $stdin.gets end |