Class: Simplerubysteps::Choice

Inherits:
State
  • Object
show all
Defined in:
lib/simplerubysteps.rb

Instance Attribute Summary collapse

Attributes inherited from State

#name, #state_machine

Instance Method Summary collapse

Methods inherited from State

#[]=

Constructor Details

#initialize(name) ⇒ Choice

Returns a new instance of Choice.



150
151
152
153
154
# File 'lib/simplerubysteps.rb', line 150

def initialize(name)
  super
  @choices = []
  @dict[:Type] = "Choice"
end

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



148
149
150
# File 'lib/simplerubysteps.rb', line 148

def choices
  @choices
end

Instance Method Details

#add(item) ⇒ Object



156
157
158
# File 'lib/simplerubysteps.rb', line 156

def add(item)
  @choices.push item
end

#add_string_matches(var, match, state) ⇒ Object



160
161
162
163
164
165
# File 'lib/simplerubysteps.rb', line 160

def add_string_matches(var, match, state)
  add ChoiceItem.new({
        :Variable => var,
        :StringMatches => match,
      }, state)
end

#default=(state) ⇒ Object



167
168
169
# File 'lib/simplerubysteps.rb', line 167

def default=(state)
  @dict[:Default] = (state.is_a? Symbol) ? state : state.name
end

#next=(state) ⇒ Object



171
172
173
# File 'lib/simplerubysteps.rb', line 171

def next=(state)
  self.default = state
end

#perform_action(output) ⇒ Object



181
182
183
184
185
# File 'lib/simplerubysteps.rb', line 181

def perform_action(output)
  @choices.each do |choice|
    choice.perform_action name, output
  end
end

#renderObject



175
176
177
178
179
# File 'lib/simplerubysteps.rb', line 175

def render
  dict = @dict.clone
  dict[:Choices] = @choices.map { |item| item.render }
  dict
end