Skip to content

Instantly share code, notes, and snippets.

@kastner
Created May 20, 2014 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastner/5110b56349aaa9a07b13 to your computer and use it in GitHub Desktop.
Save kastner/5110b56349aaa9a07b13 to your computer and use it in GitHub Desktop.
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