Class: Octopolo::Question
- Inherits:
-
Object
- Object
- Octopolo::Question
- Includes:
- CLIWrapper
- Defined in:
- lib/octopolo/question.rb
Instance Attribute Summary collapse
-
#add_label_based_on_boolean ⇒ Object
Returns the value of attribute add_label_based_on_boolean.
-
#choices ⇒ Object
Returns the value of attribute choices.
-
#prompt ⇒ Object
Asks the client to ask the question and returns the answer in string form.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from CLIWrapper
Instance Method Summary collapse
-
#ask ⇒ Object
Asks the client to ask the question and returns the answer in string form.
-
#ask_boolean ⇒ Object
Asks the client to ask the true/false question and returns the answer in boolean form UNLESS we get true and we want to add a label, in which case it will return the name of the label in string form.
-
#initialize(options) ⇒ Question
constructor
A new instance of Question.
-
#prompt_multiline ⇒ Object
Asks the client to ask the question and returns the answer in string form.
-
#prompt_secret ⇒ Object
Asks the client to ask the question and returns the answer in string form.
-
#run_based_on_type ⇒ Object
Runs the question method based on what the :type was initialized as.
Constructor Details
#initialize(options) ⇒ Question
Returns a new instance of Question.
7 8 9 10 11 12 |
# File 'lib/octopolo/question.rb', line 7 def initialize() self.prompt = [:prompt] self.type = [:type] || nil self.choices = [:choices] || nil self.add_label_based_on_boolean = [:add_label_based_on_boolean] || nil end |
Instance Attribute Details
#add_label_based_on_boolean ⇒ Object
Returns the value of attribute add_label_based_on_boolean.
5 6 7 |
# File 'lib/octopolo/question.rb', line 5 def add_label_based_on_boolean @add_label_based_on_boolean end |
#choices ⇒ Object
Returns the value of attribute choices.
5 6 7 |
# File 'lib/octopolo/question.rb', line 5 def choices @choices end |
#prompt ⇒ Object
Asks the client to ask the question and returns the answer in string form.
51 52 53 |
# File 'lib/octopolo/question.rb', line 51 def prompt @prompt end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/octopolo/question.rb', line 5 def type @type end |
Instance Method Details
#ask ⇒ Object
Asks the client to ask the question and returns the answer in string form.
33 34 35 |
# File 'lib/octopolo/question.rb', line 33 def ask cli.ask(@prompt, @choices) end |
#ask_boolean ⇒ Object
Asks the client to ask the true/false question and returns the answer in boolean form UNLESS we get true and we want to add a label, in which case it will return the name of the label in string form.
40 41 42 43 44 45 46 47 48 |
# File 'lib/octopolo/question.rb', line 40 def ask_boolean response = cli.ask_boolean(@prompt) if response && @add_label_based_on_boolean @add_label_based_on_boolean[:label_name] else response end end |
#prompt_multiline ⇒ Object
Asks the client to ask the question and returns the answer in string form.
56 57 58 |
# File 'lib/octopolo/question.rb', line 56 def prompt_multiline cli.prompt_multiline(@prompt) end |
#prompt_secret ⇒ Object
Asks the client to ask the question and returns the answer in string form.
61 62 63 |
# File 'lib/octopolo/question.rb', line 61 def prompt_secret cli.prompt_secret(@prompt) end |
#run_based_on_type ⇒ Object
Runs the question method based on what the :type was initialized as.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/octopolo/question.rb', line 15 def run_based_on_type case @type when :ask ask when :ask_boolean ask_boolean when :prompt prompt when :prompt_multiline prompt_multiline when :prompt_secret prompt_secret else "Question type is invalid... not asking a question." end end |