Class: SynFlowFactory::TransitionSet

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

Instance Method Summary collapse

Constructor Details

#initializeTransitionSet

Returns a new instance of TransitionSet.



66
67
68
# File 'lib/syn_flow.rb', line 66

def initialize
  @val = {}
end

Instance Method Details

#<<(transition) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/syn_flow.rb', line 105

def << ( transition )
  case transition
  when Array
    add(*transition)
  when Hash
    transition.each do |src, x|
      unless x.is_a? Hash
        raise TypeError, "bad transtion: #{transition.inspect}"
      end
      x.each do |label, dest|
        add(src, label, dest)
      end
    end
  when Transition
    add_transition(transition)
  else
    raise TypeError, "bad transtion: #{transition.inspect}"
  end
  self
end

#add(src, label, dest) ⇒ Object



91
92
93
94
# File 'lib/syn_flow.rb', line 91

def add ( src, label, dest )
  @val[src] ||= {}
  @val[src][label] = dest
end

#add_transition(t) ⇒ Object



96
97
98
# File 'lib/syn_flow.rb', line 96

def add_transition ( t )
  add(t.src, t.label, t.dest)
end

#delta(src, label) ⇒ Object



100
101
102
103
# File 'lib/syn_flow.rb', line 100

def delta ( src, label )
  @val[src] ||= {}
  @val[src][label]
end

#include?(*a) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/syn_flow.rb', line 70

def include? ( *a )
  case a.size
  when 1
    t = a[0]
    case t
    when Array
      return include?(*t)
    else
      return delta(t.src, t.label) == t.dest
    end
  when 2
    state, label = a
    return ! delta(state, label).nil?
  when 3
    state, label, dest = a
    return delta(state, label) == dest
  else
    raise ArgumentError, 'bad transition'
  end
end