Class: HTAuth::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/htauth/console.rb

Overview

Internal: Utility class for managing console input/output

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout) ⇒ Console

Returns a new instance of Console.



12
13
14
15
# File 'lib/htauth/console.rb', line 12

def initialize(input = $stdin, output = $stdout)
  @input = input
  @output = output
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



9
10
11
# File 'lib/htauth/console.rb', line 9

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/htauth/console.rb', line 10

def output
  @output
end

Instance Method Details

#ask(prompt) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
# File 'lib/htauth/console.rb', line 21

def ask(prompt)
  output.print prompt
  answer = read_answer
  output.puts
  raise ConsoleError, "No input given" if answer.nil?
  answer.strip!
  raise ConsoleError, "No input given" if answer.length == 0
  return answer
end

#read_answerObject



31
32
33
# File 'lib/htauth/console.rb', line 31

def read_answer
  input.noecho(&:gets)
end

#say(msg) ⇒ Object



17
18
19
# File 'lib/htauth/console.rb', line 17

def say(msg)
  @output.puts msg
end