Class: Vop::TestableShellInput
- Inherits:
-
Object
- Object
- Vop::TestableShellInput
- Defined in:
- lib/vop/shell/shell_input_testable.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#exit ⇒ Object
readonly
Returns the value of attribute exit.
-
#fail_if_out_of_answers ⇒ Object
Returns the value of attribute fail_if_out_of_answers.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
-
#initialize ⇒ TestableShellInput
constructor
A new instance of TestableShellInput.
- #read(prompt) ⇒ Object
Constructor Details
#initialize ⇒ TestableShellInput
Returns a new instance of TestableShellInput.
9 10 11 12 13 14 |
# File 'lib/vop/shell/shell_input_testable.rb', line 9 def initialize @answers = [] @exit = false @prompt = nil @fail_if_out_of_answers = true end |
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
5 6 7 |
# File 'lib/vop/shell/shell_input_testable.rb', line 5 def answers @answers end |
#exit ⇒ Object (readonly)
Returns the value of attribute exit.
6 7 8 |
# File 'lib/vop/shell/shell_input_testable.rb', line 6 def exit @exit end |
#fail_if_out_of_answers ⇒ Object
Returns the value of attribute fail_if_out_of_answers.
7 8 9 |
# File 'lib/vop/shell/shell_input_testable.rb', line 7 def fail_if_out_of_answers @fail_if_out_of_answers end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
6 7 8 |
# File 'lib/vop/shell/shell_input_testable.rb', line 6 def prompt @prompt end |
Instance Method Details
#read(prompt) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vop/shell/shell_input_testable.rb', line 16 def read(prompt) @prompt = prompt answer = @answers.shift if answer.nil? && @fail_if_out_of_answers unless @exit raise "no more pre-defined answers (asked for '#{prompt}')" end end answer end |