Class: Simplerubysteps::Choice

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

Instance Attribute Summary collapse

Attributes inherited from State

#name, #state_machine

Instance Method Summary collapse

Methods inherited from State

#[]=, #error_catch, #error_retry, #task_timeout

Constructor Details

#initialize(name) ⇒ Choice

Returns a new instance of Choice.



291
292
293
294
295
# File 'lib/simplerubysteps/model.rb', line 291

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

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



289
290
291
# File 'lib/simplerubysteps/model.rb', line 289

def choices
  @choices
end

Instance Method Details

#add(item) ⇒ Object



297
298
299
# File 'lib/simplerubysteps/model.rb', line 297

def add(item)
  @choices.push item
end

#add_string_matches(var, match, state) ⇒ Object



301
302
303
304
305
306
# File 'lib/simplerubysteps/model.rb', line 301

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

#default=(state) ⇒ Object



308
309
310
# File 'lib/simplerubysteps/model.rb', line 308

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

#next=(state) ⇒ Object



312
313
314
# File 'lib/simplerubysteps/model.rb', line 312

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

#perform_action(output) ⇒ Object



322
323
324
325
326
# File 'lib/simplerubysteps/model.rb', line 322

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

#renderObject



316
317
318
319
320
# File 'lib/simplerubysteps/model.rb', line 316

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