Created
March 6, 2017 17:09
-
-
Save kellyfelkins/b7c7d0247da42d542ef7efe8d23798b1 to your computer and use it in GitHub Desktop.
Simple example of unix style filter written in ruby. This one filters a dot file created by the rails-erd gem in order to put specializations in subgraphs.
This file contains 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
#!/usr/bin/env ruby | |
BEGIN { | |
clusters = Hash.new {|h, k| h[k] = []} | |
} | |
ARGF.each_line do |line| | |
case line | |
when /\s*(\w+) -> .+?grey60/ | |
clusters[$1] << line | |
when %r|\s*\}\s*| | |
else | |
puts line | |
end | |
end | |
END { | |
puts "graph [style=filled, color=aliceblue];" | |
clusters.each do |name, edges| | |
puts "subgraph cluster_#{name} {" | |
puts " label=#{name};" | |
edges.each do |edge| | |
puts " #{edge}" | |
end | |
puts "}" | |
end | |
puts "}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment