Class: HTAuth::Console
- Inherits:
-
Object
- Object
- HTAuth::Console
- Defined in:
- lib/htauth/console.rb
Overview
Internal: Utility class for managing console input/output
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #ask(prompt) ⇒ Object
-
#initialize(input = $stdin, output = $stdout) ⇒ Console
constructor
A new instance of Console.
- #read_answer ⇒ Object
- #say(msg) ⇒ Object
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
#input ⇒ Object (readonly)
Returns the value of attribute input.
9 10 11 |
# File 'lib/htauth/console.rb', line 9 def input @input end |
#output ⇒ Object (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
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_answer ⇒ Object
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 |