Class: Reviewer::Prompt
- Inherits:
-
Object
- Object
- Reviewer::Prompt
- Defined in:
- lib/reviewer/prompt.rb
Overview
Simple interactive prompt for yes/no questions. Wraps input/output streams for testability.
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
-
#initialize(input: $stdin, output: $stdout) ⇒ Prompt
constructor
Creates an interactive prompt for yes/no questions.
-
#yes?(message) ⇒ Boolean
Asks a yes/no question and returns the boolean result.
Constructor Details
#initialize(input: $stdin, output: $stdout) ⇒ Prompt
Creates an interactive prompt for yes/no questions
14 15 16 17 |
# File 'lib/reviewer/prompt.rb', line 14 def initialize(input: $stdin, output: $stdout) @input = input @output = output end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
7 8 9 |
# File 'lib/reviewer/prompt.rb', line 7 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/reviewer/prompt.rb', line 7 def output @output end |
Instance Method Details
#yes?(message) ⇒ Boolean
Asks a yes/no question and returns the boolean result. Returns false in non-interactive contexts (CI, pipes).
24 25 26 27 28 29 30 |
# File 'lib/reviewer/prompt.rb', line 24 def yes?() return false unless interactive? @output.print "#{message} (y/n) " response = @input.gets&.strip&.downcase response&.start_with?('y') || false end |