Sha256: 1e8070082327af229ca20f808fc17e4c884fb736ed73b90c6fedeeee18bfe350
Contents?: true
Size: 889 Bytes
Versions: 26
Compression:
Stored size: 889 Bytes
Contents
#!/usr/bin/env ruby require 'tree_node' class Node include Tree::Node attr_accessor :level attr_accessor :label def initialize(level, label) @level = level @label = label end def to_s "<Node level:#{level}, label:#{label}, children: #{children.size}>" end def relations children.map do |child| "#{label.inspect} -> #{child.label.inspect}" end end end SPACER = /\s\s\s\s/ nodes = [] STDIN.each_line do |line| label = line.chomp.gsub(SPACER, '') level = line.chomp.scan(SPACER).size node = Node.new(level, label) nodes.push(node) nodes.reverse.find do |previous_node| if previous_node.level < node.level previous_node.add_child(node) end end end puts 'digraph diagram {' puts "rankdir = #{ARGV[0] || 'LR'};" nodes.first.map(:down) do |node| node.relations.each do |relation| puts relation end end puts '}'
Version data entries
26 entries across 26 versions & 1 rubygems
Version | Path |
---|---|
ix-cli-0.0.6 | bin/ix-diagram |
ix-cli-0.0.5 | bin/ix-diagram |
ix-cli-0.0.4 | bin/ix-diagram |
ix-cli-0.0.3 | bin/ix-diagram |
ix-cli-0.0.2 | bin/ix-diagram |
ix-cli-0.0.1 | bin/ix-diagram |