aboutsummaryrefslogtreecommitdiff
path: root/lib/node.rb
diff options
context:
space:
mode:
authorNathan Lasseter <nathan@4574.co.uk>2014-03-29 16:23:06 +0000
committerNathan Lasseter <nathan@4574.co.uk>2014-03-29 16:23:06 +0000
commitd9fbb2c4900b008daa9c5e0302677f9d1674a473 (patch)
treece4a5ae23db310d064c379e0148dd621e845ca61 /lib/node.rb
parent4b1a4a8e9dbe9ea46b596a4578f7e3d51b235a15 (diff)
Begun modularising
Diffstat (limited to 'lib/node.rb')
-rw-r--r--lib/node.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/node.rb b/lib/node.rb
new file mode 100644
index 0000000..5875e38
--- /dev/null
+++ b/lib/node.rb
@@ -0,0 +1,44 @@
+module VFSM
+ class Node
+ def initialize id, accepting = false
+ @id = id
+ @accepting = accepting
+ @edges = []
+ end
+
+ def id
+ return @id
+ end
+
+ def accepting! accepting=true
+ @accepting = accepting
+ end
+
+ def accepting?
+ return @accepting
+ end
+
+ def pushedge on, to
+ tempto = @edges.select do |edge|
+ edge[0] == on
+ end
+ @edges.push [on, to]
+ end
+
+ def goto on
+ to = @edges.select do |edge|
+ edge[0] == on
+ end
+
+ if to.length == 0 then
+ return :reject
+ else
+ ret = []
+ to.each do |x|
+ ret.push x[1]
+ end
+ return ret
+ end
+ end
+ end
+end