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.



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

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

Instance Attribute Details

#choicesObject (readonly)

Returns the value of attribute choices.



165
166
167
# File 'lib/simplerubysteps/model.rb', line 165

def choices
  @choices
end

Instance Method Details

#add(item) ⇒ Object



173
174
175
# File 'lib/simplerubysteps/model.rb', line 173

def add(item)
  @choices.push item
end

#add_string_matches(var, match, state) ⇒ Object



177
178
179
180
181
182
# File 'lib/simplerubysteps/model.rb', line 177

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

#default=(state) ⇒ Object



184
185
186
# File 'lib/simplerubysteps/model.rb', line 184

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

#next=(state) ⇒ Object



188
189
190
# File 'lib/simplerubysteps/model.rb', line 188

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

#perform_action(output) ⇒ Object



198
199
200
201
202
# File 'lib/simplerubysteps/model.rb', line 198

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

#renderObject



192
193
194
195
196
# File 'lib/simplerubysteps/model.rb', line 192

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