Class: StateShifter::State

Inherits:
Object
  • Object
show all
Defined in:
lib/state_shifter/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, initial = false) ⇒ State

Returns a new instance of State.



8
9
10
11
12
13
14
# File 'lib/state_shifter/state.rb', line 8

def initialize name, initial=false
  @name = name
  @events = {}
  @initial = initial
  @entry_callback = nil
  @entry_callback_args = nil
end

Instance Attribute Details

#entry_callbackObject

Returns the value of attribute entry_callback.



6
7
8
# File 'lib/state_shifter/state.rb', line 6

def entry_callback
  @entry_callback
end

#entry_callback_argsObject

Returns the value of attribute entry_callback_args.



6
7
8
# File 'lib/state_shifter/state.rb', line 6

def entry_callback_args
  @entry_callback_args
end

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/state_shifter/state.rb', line 5

def events
  @events
end

#initialObject (readonly)

Returns the value of attribute initial.



5
6
7
# File 'lib/state_shifter/state.rb', line 5

def initial
  @initial
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/state_shifter/state.rb', line 5

def name
  @name
end

Instance Method Details

#draw(graph, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/state_shifter/state.rb', line 28

def draw graph, options
  node = graph.add_nodes(@name.to_s,
                        :label => @name.to_s,
                        :width => '1',
                        :height => '1',
                        :shape => final? ? 'doublecircle' : 'ellipse'
                       )

  graph.add_edges(graph.add_nodes('starting_state', :shape => 'point'), node) if initial?

  node
end

#final?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/state_shifter/state.rb', line 24

def final?
  @events.empty?
end

#has_entry_callback?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/state_shifter/state.rb', line 16

def has_entry_callback?
  !@entry_callback.nil?
end

#initial?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/state_shifter/state.rb', line 20

def initial?
  @initial
end