Created
May 20, 2014 20:14
-
-
Save kastner/5110b56349aaa9a07b13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = "[{id: 'lookingAtFoo0', inResponseTo: 'looking at foo', onFinish: 'delete foo'}, {name: 'looking at foo', inResponseTo: 'found foo', onFinish: 'clikced foo'}]" | |
nodes = {} | |
class Node | |
def initialize(thisId) | |
self.id = thisId | |
end | |
attr_accessor :id, :inResponseTo, :onFinish | |
end | |
input.each do |node| | |
irt = nodes[node[:inResponseTo]] || Node.new(node[:inResponseTo]) | |
onf = nodes[node[:onFinish]] || Node.new(node[:onFinish]) | |
newNode = nodes[node[:name]] || Node.new(node[:name]) | |
newNode.inResponseTo = irt | |
newNode.onFinish = onf | |
nodes[node[:name]] = newNode | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment