Skip to content

Instantly share code, notes, and snippets.

@mbernson
Created February 26, 2013 13:00
Show Gist options
  • Save mbernson/5038244 to your computer and use it in GitHub Desktop.
Save mbernson/5038244 to your computer and use it in GitHub Desktop.
# This script converts an exported mind map from MindNode
# to JSON, for instance for using with D3.js (http://d3js.org).
#
# Example: `./mindmap.rb > structure.json`
$LOAD_PATH.unshift '.'
require 'json'
file = File.open('./mind-map.txt')
class String
def to_node
{ "name" => self }
end
end
map = {}
file.each_line do |line|
level = line.count "\t"
node = map
level.times do
node = node["children"].last
end
node["children"] ||= []
node["children"] << line.strip.to_node
end
puts JSON.pretty_generate(map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment