Class: HighlineWrapper
- Inherits:
-
Object
- Object
- HighlineWrapper
- Defined in:
- lib/highline_wrapper.rb,
lib/highline_wrapper/version.rb,
lib/highline_wrapper/question.rb,
lib/highline_wrapper/yes_no_question.rb,
lib/highline_wrapper/checkbox_question.rb,
lib/highline_wrapper/open_ended_question.rb,
lib/highline_wrapper/multiple_choice_question.rb
Defined Under Namespace
Classes: CheckboxQuestion, MultipleChoiceQuestion, OpenEndedQuestion, Question, YesNoQuestion
Constant Summary collapse
- VERSION =
'3.0.0'
Instance Method Summary collapse
-
#ask(prompt, options = {}) ⇒ Object
Returns: the answer to the question (string).
-
#ask_checkbox(prompt, choices, options = {}) ⇒ Object
Returns: the selections chosen as an array of hashes (array) e.g.
-
#ask_multiple_choice(prompt, choices, options = {}) ⇒ Object
Returns: the selection in a hash (hash) e.g.
-
#ask_yes_no(prompt, options = {}) ⇒ Object
Returns: yes for true, no for false (boolean).
Instance Method Details
#ask(prompt, options = {}) ⇒ Object
Returns: the answer to the question (string)
prompt: the prompt for the question (string) options: various options to pass to the questions (hash)
indicate_default_message: whether to tell the terminal what the default value selected is if the question
is skipped (boolean - defaults to true)
secret: whether the terminal should hide the typed value (boolean - defaults to false)
default: the default selection (string - defaults to '')
required: whether the question is required or not (boolean - defaults to false)
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/highline_wrapper.rb', line 21 def ask(prompt, = {}) defaults = { indicate_default_message: true, secret: false, default: '', required: false } = defaults.merge() HighlineWrapper::OpenEndedQuestion.ask(prompt, ) end |
#ask_checkbox(prompt, choices, options = {}) ⇒ Object
Returns: the selections chosen as an array of hashes (array)
e.g. [{ value: 'a' }, { value: 'c' }]
e.g. [{ value: 'a', index: 0 }, { value: 'c', index: 2 }])
prompt: the prompt for the question (string) choices: a list of string options (array) (e.g. [ ‘a’, ‘b’, ‘c’ ]) options: various options to pass to the questions (hash)
indicate_default_message: whether to tell the terminal what the default value selected is if the question
is skipped (boolean - defaults to true)
with_indexes: whether to return the indexes of the selections (boolean - defaults to false)
defaults: the default selections if the user skips the question (array - defaults to [])
required: whether the question is required or not (boolean - defaults to false)
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/highline_wrapper.rb', line 85 def ask_checkbox(prompt, choices, = {}) defaults = { indicate_default_message: true, with_indexes: false, defaults: [], required: false } = defaults.merge() HighlineWrapper::CheckboxQuestion.ask(prompt, choices, ) end |
#ask_multiple_choice(prompt, choices, options = {}) ⇒ Object
Returns: the selection in a hash (hash)
e.g. { value: 'c' }
e.g. { value: 'c', index: 2 }
prompt: the prompt for the question (string) choices: a list of string options (array) (e.g. [ ‘a’, ‘b’, ‘c’ ]) options: various options to pass to the questions (hash)
indicate_default_message: whether to tell the terminal what the default value selected is if the question
is skipped (boolean - defaults to true)
with_index: whether to return the index of the selection (boolean - defaults to false)
default: the default selection if the user skips the question (string - defaults to nil)
required: whether the question is required or not (boolean - defaults to false)
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/highline_wrapper.rb', line 62 def ask_multiple_choice(prompt, choices, = {}) defaults = { indicate_default_message: true, with_index: false, default: nil, required: false } = defaults.merge() HighlineWrapper::MultipleChoiceQuestion.ask(prompt, choices, ) end |
#ask_yes_no(prompt, options = {}) ⇒ Object
Returns: yes for true, no for false (boolean)
prompt: the prompt for the question (string) options: various options to pass to the questions (hash)
indicate_default_message: whether to tell the terminal what the default value selected is if the question
is skipped (boolean - defaults to true)
default: the default selection (boolean - defaults to true)
required: whether the question is required or not (boolean - defaults to false)
40 41 42 43 44 45 46 47 48 |
# File 'lib/highline_wrapper.rb', line 40 def ask_yes_no(prompt, = {}) defaults = { indicate_default_message: true, default: true, required: false } = defaults.merge() HighlineWrapper::YesNoQuestion.ask(prompt, ) end |