Class: Giraffe
- Inherits:
-
Object
- Object
- Giraffe
- Defined in:
- lib/giraffe.rb
Constant Summary collapse
- PARTIAL_REGEX =
/render\W+:partial\W+=>\W+"([\w\/]+)"/
Class Method Summary collapse
Instance Method Summary collapse
- #generate(outfile) ⇒ Object
-
#initialize(path) ⇒ Giraffe
constructor
A new instance of Giraffe.
- #parse_file(path) ⇒ Object
- #write_graph(outfile) ⇒ Object
Constructor Details
#initialize(path) ⇒ Giraffe
Returns a new instance of Giraffe.
11 12 13 14 15 |
# File 'lib/giraffe.rb', line 11 def initialize(path) @path = path @graph = GraphViz.new(:G, :type => :digraph) @nodes = {} end |
Class Method Details
.generate(path, outfile) ⇒ Object
7 8 9 |
# File 'lib/giraffe.rb', line 7 def self.generate(path, outfile) new(path).generate(outfile) end |
Instance Method Details
#generate(outfile) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/giraffe.rb', line 17 def generate(outfile) Dir.chdir(@path) do Dir.glob("**/*.*").each do |file| parse_file(file) end end write_graph(outfile) end |
#parse_file(path) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/giraffe.rb', line 30 def parse_file(path) File.open(path, 'r').each_line do |line| if match = line.match(PARTIAL_REGEX) add_edge(normalize(path), find_template(partial_path(path, match[1]))) end end end |
#write_graph(outfile) ⇒ Object
26 27 28 |
# File 'lib/giraffe.rb', line 26 def write_graph(outfile) @graph.output( :png => outfile ) end |