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.27 bin/ix-diagram
ix-cli-0.0.26 bin/ix-diagram
ix-cli-0.0.25 bin/ix-diagram
ix-cli-0.0.24 bin/ix-diagram
ix-cli-0.0.23 bin/ix-diagram
ix-cli-0.0.22 bin/ix-diagram
ix-cli-0.0.21 bin/ix-diagram
ix-cli-0.0.20 bin/ix-diagram
ix-cli-0.0.19 bin/ix-diagram
ix-cli-0.0.18 bin/ix-diagram
ix-cli-0.0.17 bin/ix-diagram
ix-cli-0.0.16 bin/ix-diagram
ix-cli-0.0.15 bin/ix-diagram
ix-cli-0.0.14 bin/ix-diagram
ix-cli-0.0.13 bin/ix-diagram
ix-cli-0.0.12 bin/ix-diagram
ix-cli-0.0.11 bin/ix-diagram
ix-cli-0.0.10 bin/ix-diagram
ix-cli-0.0.9 bin/ix-diagram
ix-cli-0.0.7 bin/ix-diagram