lib/cabbage/dotfile/parser.rb
# a dotfile has four components:
# graph_type, header, nodes, connections
a dotfile has four components:
graph_type, header, nodes, connections
a dotfile has four components : graph_type header nodes connections
def parse_dotfile
      raw_chunk = @raw_dotfile.split("{")[1].split("}")[0].strip
      raw_header = raw_chunk.match(/([\w\s*=".,\s\[\]_\\]+;)*/m)[0]
      raw_body = raw_chunk.sub(raw_header, "")
      raw_connections = raw_body.split(">];")[-1].strip
      raw_tables = raw_body.split(">];")[0 .. -2].join(">];").strip + " \n>];"
      @graph_type = @raw_dotfile.match(/\A\s*((?:di)?graph)/)[1]
      @title = @raw_dotfile.match(/\A\s*(?:di)?graph\s*(\w+)/)[1]
      @header = parse_header(raw_header, ";")
      @nodes = parse_nodes(raw_tables)
      @connections = parse_connections(raw_connections)
    end
def parse_dotfile raw_chunk = @raw_dotfile . split ( "{" ) [ 1 ] . split ( "}" ) [ 0 ] . strip raw_header = raw_chunk . match ( / ([ \w \s *="., \s \[ \] _ \\ ]+;)* /m ) [ 0 ] raw_body = raw_chunk . sub ( raw_header , "" ) raw_connections = raw_body . split ( ">];" ) [ - 1 ] . strip raw_tables = raw_body . split ( ">];" ) [ 0 .. - 2 ] . join ( ">];" ) . strip + " \n>];" @graph_type = @raw_dotfile . match ( / \A \s *((?:di)?graph) / ) [ 1 ] @title = @raw_dotfile . match ( / \A \s *(?:di)?graph \s *( \w +) / ) [ 1 ] @header = parse_header ( raw_header , ";" ) @nodes = parse_nodes ( raw_tables ) @connections = parse_connections ( raw_connections ) end
a dotfile has four components:
graph_type, header, nodes, connections
a dotfile has four components : graph_type header nodes connections
# the chunk is everything inside '{}' # pull out the header # find body by chopping header off chunk # split the body on '>];', which delimits the tables section # split out the tables section from the body # assemble the output hash