Class: Workflow::State
- Inherits:
-
Object
- Object
- Workflow::State
- Includes:
- Comparable
- Defined in:
- lib/workflow/state.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#name ⇒ Object
Returns the value of attribute name.
-
#on_entry ⇒ Object
Returns the value of attribute on_entry.
-
#on_exit ⇒ Object
Returns the value of attribute on_exit.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
Instance Method Summary collapse
- #<=>(other_state) ⇒ Object
- #draw(graph) ⇒ Object
-
#initialize(name, spec, meta = {}) ⇒ State
constructor
A new instance of State.
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(name, spec, meta = {}) ⇒ State
Returns a new instance of State.
6 7 8 |
# File 'lib/workflow/state.rb', line 6 def initialize(name, spec, = {}) @name, @spec, @events, @meta = name, spec, EventCollection.new, end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
3 4 5 |
# File 'lib/workflow/state.rb', line 3 def events @events end |
#meta ⇒ Object
Returns the value of attribute meta.
3 4 5 |
# File 'lib/workflow/state.rb', line 3 def @meta end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/workflow/state.rb', line 3 def name @name end |
#on_entry ⇒ Object
Returns the value of attribute on_entry.
3 4 5 |
# File 'lib/workflow/state.rb', line 3 def on_entry @on_entry end |
#on_exit ⇒ Object
Returns the value of attribute on_exit.
3 4 5 |
# File 'lib/workflow/state.rb', line 3 def on_exit @on_exit end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
4 5 6 |
# File 'lib/workflow/state.rb', line 4 def spec @spec end |
Instance Method Details
#<=>(other_state) ⇒ Object
29 30 31 32 33 |
# File 'lib/workflow/state.rb', line 29 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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/workflow/state.rb', line 10 def draw(graph) defaults = { :label => to_s, :width => '1', :height => '1', :shape => 'ellipse' } node = graph.add_nodes(to_s, defaults.merge()) # Add open arrow for initial state # graph.add_edge(graph.add_node('starting_state', :shape => 'point'), node) if initial? node end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/workflow/state.rb', line 36 def to_s "#{name}" end |
#to_sym ⇒ Object
40 41 42 |
# File 'lib/workflow/state.rb', line 40 def to_sym name.to_sym end |