Skip to content

Instantly share code, notes, and snippets.

@kellyfelkins
Created March 6, 2017 17:09
Show Gist options
  • Save kellyfelkins/b7c7d0247da42d542ef7efe8d23798b1 to your computer and use it in GitHub Desktop.
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.
#!/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