Class: Vop::TestableShellInput

Inherits:
Object
  • Object
show all
Defined in:
lib/vop/shell/shell_input_testable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestableShellInput

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

#answersObject

Returns the value of attribute answers.



5
6
7
# File 'lib/vop/shell/shell_input_testable.rb', line 5

def answers
  @answers
end

#exitObject (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_answersObject

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

#promptObject (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