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.



254
255
256
257
258
# File 'lib/simplerubysteps/model.rb', line 254

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

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



252
253
254
# File 'lib/simplerubysteps/model.rb', line 252

def choices
  @choices
end

Instance Method Details

#add(item) ⇒ Object



260
261
262
# File 'lib/simplerubysteps/model.rb', line 260

def add(item)
  @choices.push item
end

#add_string_matches(var, match, state) ⇒ Object



264
265
266
267
268
269
# File 'lib/simplerubysteps/model.rb', line 264

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

#default=(state) ⇒ Object



271
272
273
# File 'lib/simplerubysteps/model.rb', line 271

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

#next=(state) ⇒ Object



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

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

#perform_action(output) ⇒ Object



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

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

#renderObject



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

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