Class: EdgeStateMachine::State

Inherits:
Object
  • Object
show all
Defined in:
lib/edge-state-machine/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ State

Returns a new instance of State.



5
6
7
8
9
# File 'lib/edge-state-machine/state.rb', line 5

def initialize(name, &block)
  @name = name
  @options = Hash.new
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/edge-state-machine/state.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/edge-state-machine/state.rb', line 3

def options
  @options
end

Instance Method Details

#==(st) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/edge-state-machine/state.rb', line 37

def ==(st)
  if st.is_a? Symbol
    name == st
  elsif st.is_a? String
    name == st
  else
    name == st.name
  end
end

#display_nameObject



33
34
35
# File 'lib/edge-state-machine/state.rb', line 33

def display_name
  @display_name ||= name.to_s.gsub(/_/, ' ').capitalize
end

#enter(method = nil, &block) ⇒ Object



11
12
13
# File 'lib/edge-state-machine/state.rb', line 11

def enter(method = nil, &block)
  @options[:enter] = method.nil? ? block : method
end

#execute_action(action, base) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/edge-state-machine/state.rb', line 19

def execute_action(action, base)
  action = @options[action.to_sym]
  case action
  when Symbol, String
    base.send(action)
  when Proc
    action.call(base)
  end
end

#exit(method = nil, &block) ⇒ Object



15
16
17
# File 'lib/edge-state-machine/state.rb', line 15

def exit(method = nil, &block)
  @options[:exit] = method.nil? ? block : method
end

#use_display_name(display_name) ⇒ Object



29
30
31
# File 'lib/edge-state-machine/state.rb', line 29

def use_display_name(display_name)
  @display_name = display_name
end