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

#[]=

Constructor Details

#initialize(name) ⇒ Choice

Returns a new instance of Choice.



275
276
277
278
279
# File 'lib/simplerubysteps/model.rb', line 275

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

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



273
274
275
# File 'lib/simplerubysteps/model.rb', line 273

def choices
  @choices
end

Instance Method Details

#add(item) ⇒ Object



281
282
283
# File 'lib/simplerubysteps/model.rb', line 281

def add(item)
  @choices.push item
end

#add_string_matches(var, match, state) ⇒ Object



285
286
287
288
289
290
# File 'lib/simplerubysteps/model.rb', line 285

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

#default=(state) ⇒ Object



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

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

#next=(state) ⇒ Object



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

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

#perform_action(output) ⇒ Object



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

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

#renderObject



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

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