Class: TTY::Prompt::ConfirmQuestion
- Defined in:
- lib/tty/prompt/confirm_question.rb
Constant Summary
Constants inherited from Question
Instance Attribute Summary
Attributes inherited from Question
#message, #messages, #modifier, #validation
Instance Method Summary collapse
- #call(message, &block) ⇒ Object
-
#initialize(prompt, options = {}) ⇒ ConfirmQuestion
constructor
Create confirmation question.
-
#negative(value = (not_set = true)) ⇒ Object
Set value for matching negative choice.
- #negative? ⇒ Boolean
-
#positive(value = (not_set = true)) ⇒ Object
Set value for matching positive choice.
- #positive? ⇒ Boolean
-
#render_question ⇒ String
private
Render confirmation question.
-
#suffix(value = (not_set = true)) ⇒ Object
Set question suffix.
- #suffix? ⇒ Boolean
Methods inherited from Question
#convert, #convert?, #convert_result, #default, #default?, #echo, #in, #in?, #inspect, #message_for, #modify, #process_input, #raw, #read_input, #refresh, #render, #render_error, #required, #to_s, #validate, #validation?
Constructor Details
#initialize(prompt, options = {}) ⇒ ConfirmQuestion
Create confirmation question
17 18 19 20 21 22 |
# File 'lib/tty/prompt/confirm_question.rb', line 17 def initialize(prompt, = {}) super @suffix = .fetch(:suffix) { UndefinedSetting } @positive = .fetch(:positive) { UndefinedSetting } @negative = .fetch(:negative) { UndefinedSetting } end |
Instance Method Details
#call(message, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/tty/prompt/confirm_question.rb', line 60 def call(, &block) return if Utils.blank?() @message = block.call(self) if block setup_defaults render end |
#negative(value = (not_set = true)) ⇒ Object
Set value for matching negative choice
55 56 57 58 |
# File 'lib/tty/prompt/confirm_question.rb', line 55 def negative(value = (not_set = true)) return @negative if not_set @negative = value end |
#negative? ⇒ Boolean
28 29 30 |
# File 'lib/tty/prompt/confirm_question.rb', line 28 def negative? @negative != UndefinedSetting end |
#positive(value = (not_set = true)) ⇒ Object
Set value for matching positive choice
47 48 49 50 |
# File 'lib/tty/prompt/confirm_question.rb', line 47 def positive(value = (not_set = true)) return @positive if not_set @positive = value end |
#positive? ⇒ Boolean
24 25 26 |
# File 'lib/tty/prompt/confirm_question.rb', line 24 def positive? @positive != UndefinedSetting end |
#render_question ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render confirmation question
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tty/prompt/confirm_question.rb', line 73 def render_question header = "#{@prefix}#{} " if !@done header += @prompt.decorate("(#{@suffix})", @help_color) + ' ' else answer = convert_result(@input) label = answer ? @positive : @negative header += @prompt.decorate(label, @active_color) end header << "\n" if @done header end |
#suffix(value = (not_set = true)) ⇒ Object
Set question suffix
39 40 41 42 |
# File 'lib/tty/prompt/confirm_question.rb', line 39 def suffix(value = (not_set = true)) return @negative if not_set @suffix = value end |
#suffix? ⇒ Boolean
32 33 34 |
# File 'lib/tty/prompt/confirm_question.rb', line 32 def suffix? @suffix != UndefinedSetting end |