Class: Octopolo::Question

Inherits:
Object
  • Object
show all
Includes:
CLIWrapper
Defined in:
lib/octopolo/question.rb

Instance Attribute Summary collapse

Attributes included from CLIWrapper

#cli

Instance Method Summary collapse

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(options)
  self.prompt = options[:prompt]
  self.type = options[:type] || nil
  self.choices = options[:choices] || nil
  self.add_label_based_on_boolean = options[:add_label_based_on_boolean] || nil
end

Instance Attribute Details

#add_label_based_on_booleanObject

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

#choicesObject

Returns the value of attribute choices.



5
6
7
# File 'lib/octopolo/question.rb', line 5

def choices
  @choices
end

#promptObject

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

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/octopolo/question.rb', line 5

def type
  @type
end

Instance Method Details

#askObject

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_booleanObject

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_multilineObject

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_secretObject

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_typeObject

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