Class: TTY2::Prompt::ConfirmQuestion
- Defined in:
- lib/tty2/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, #quiet, #raw, #read_input, #refresh, #render, #render_error, #required, #to_s, #validate, #validation?, #value, #value?
Constructor Details
#initialize(prompt, **options) ⇒ ConfirmQuestion
Create confirmation question
17 18 19 20 21 22 |
# File 'lib/tty2/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
63 64 65 66 67 68 69 70 |
# File 'lib/tty2/prompt/confirm_question.rb', line 63 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
57 58 59 60 61 |
# File 'lib/tty2/prompt/confirm_question.rb', line 57 def negative(value = (not_set = true)) return @negative if not_set @negative = value end |
#negative? ⇒ Boolean
28 29 30 |
# File 'lib/tty2/prompt/confirm_question.rb', line 28 def negative? @negative != UndefinedSetting end |
#positive(value = (not_set = true)) ⇒ Object
Set value for matching positive choice
48 49 50 51 52 |
# File 'lib/tty2/prompt/confirm_question.rb', line 48 def positive(value = (not_set = true)) return @positive if not_set @positive = value end |
#positive? ⇒ Boolean
24 25 26 |
# File 'lib/tty2/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
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tty2/prompt/confirm_question.rb', line 77 def render_question header = "#{@prefix}#{} " if !@done header += @prompt.decorate("(#{@suffix})", @help_color) + " " else answer = conversion.call(@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 43 |
# File 'lib/tty2/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/tty2/prompt/confirm_question.rb', line 32 def suffix? @suffix != UndefinedSetting end |