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.
13 14 15 16 |
# File 'lib/htauth/console.rb', line 13 def initialize(input = $stdin, output = $stdout) @input = input @output = output end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
11 12 13 |
# File 'lib/htauth/console.rb', line 11 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
11 12 13 |
# File 'lib/htauth/console.rb', line 11 def output @output end |
Instance Method Details
#ask(prompt) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/htauth/console.rb', line 22 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.empty? answer end |
#read_answer ⇒ Object
34 35 36 |
# File 'lib/htauth/console.rb', line 34 def read_answer input.noecho(&:gets) end |
#say(msg) ⇒ Object
18 19 20 |
# File 'lib/htauth/console.rb', line 18 def say(msg) @output.puts msg end |