Class: Stealth::Flow::State

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/stealth/flow/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, spec, meta = {}) ⇒ State

Returns a new instance of State.



13
14
15
# File 'lib/stealth/flow/state.rb', line 13

def initialize(name, spec, meta = {})
  @name, @spec, @events, @meta = name, spec, EventCollection.new, meta
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



10
11
12
# File 'lib/stealth/flow/state.rb', line 10

def events
  @events
end

#metaObject

Returns the value of attribute meta.



10
11
12
# File 'lib/stealth/flow/state.rb', line 10

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/stealth/flow/state.rb', line 10

def name
  @name
end

#on_entryObject

Returns the value of attribute on_entry.



10
11
12
# File 'lib/stealth/flow/state.rb', line 10

def on_entry
  @on_entry
end

#on_exitObject

Returns the value of attribute on_exit.



10
11
12
# File 'lib/stealth/flow/state.rb', line 10

def on_exit
  @on_exit
end

#specObject (readonly)

Returns the value of attribute spec.



11
12
13
# File 'lib/stealth/flow/state.rb', line 11

def spec
  @spec
end

Instance Method Details

#<=>(other_state) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/stealth/flow/state.rb', line 33

def <=>(other_state)
  states = spec.states.keys
  raise ArgumentError, "state `#{other_state}' does not exist" unless states.include?(other_state.to_sym)
  states.index(self.to_sym) <=> states.index(other_state.to_sym)
end

#draw(graph) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stealth/flow/state.rb', line 17

def draw(graph)
  defaults = {
    :label => to_s,
    :width => '1',
    :height => '1',
    :shape => 'ellipse'
  }

  node = graph.add_nodes(to_s, defaults.merge(meta))

  # Add open arrow for initial state
  # graph.add_edge(graph.add_node('starting_state', :shape => 'point'), node) if initial?

  node
end

#to_sObject



39
40
41
# File 'lib/stealth/flow/state.rb', line 39

def to_s
  "#{name}"
end

#to_symObject



43
44
45
# File 'lib/stealth/flow/state.rb', line 43

def to_sym
  name.to_sym
end