Created
August 3, 2016 00:21
-
-
Save bjeanes/f61d65a136c98dc86cdd8fefc98e1b84 to your computer and use it in GitHub Desktop.
Low effort anonymisation script a `rails-erd` generated `.dot` file (which I used to submit a Graphviz bug report)
This file contains hidden or 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
dot = ARGF.read | |
matches = Hash.new { |h, k| h[k] = "Anonymized_#{rand 9999}" } | |
replaced1 = dot.gsub(/\b"?m_([A-Za-z0-9_:]+)"?\b/) { |m| m.sub(%r|\b#{$1}\b|, matches[$1]) } | |
regexp = Regexp.union(matches.keys.map { |k| Regexp.new(k) }) | |
replaced2 = replaced1.gsub(regexp) { |m| matches[m] } | |
puts replaced2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment