Class: StateShifter::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, name, to = nil, guards = nil, callback = nil) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
10
11
# File 'lib/state_shifter/event.rb', line 5

def initialize from, name, to=nil, guards=nil, callback=nil
  @name = name
  @from = from
  @to = to
  @guards = [guards].flatten.compact
  @callback = callback
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



3
4
5
# File 'lib/state_shifter/event.rb', line 3

def callback
  @callback
end

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/state_shifter/event.rb', line 3

def from
  @from
end

#guardsObject (readonly)

Returns the value of attribute guards.



3
4
5
# File 'lib/state_shifter/event.rb', line 3

def guards
  @guards
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/state_shifter/event.rb', line 3

def name
  @name
end

#toObject (readonly)

Returns the value of attribute to.



3
4
5
# File 'lib/state_shifter/event.rb', line 3

def to
  @to
end

Instance Method Details

#draw(graph, options = {}) ⇒ Object



21
22
23
24
# File 'lib/state_shifter/event.rb', line 21

def draw(graph, options = {})
  to = @to ? @to : @from
  graph.add_edges(@from.to_s, to.to_s, :label => @name.to_s)
end

#has_callback?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/state_shifter/event.rb', line 17

def has_callback?
  !@callback.nil?
end

#has_guards?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/state_shifter/event.rb', line 13

def has_guards?
  !@guards.nil?
end