2 # Parses a file, and store the results in files on disk.
4 # This method primarily exists for the benefit of the Ohloh analysis engine,
5 # which prefers to store interim results in files on disk. It is unlikely to be
6 # useful to the general public.
8 # A subdirectory is created for each language found in the target file.
9 # Within each language subdirectory, separate files are created for code, comments, and blanks.
11 # The 'code' file contains code lines, the 'comments' file contains comment lines, and the 'blanks'
12 # file contains a count of the number of blank lines in the file.
13 def self.parse_to_dir(args)
15 :dir, # directory to parse to
16 :buffer, # buffer contents of the what we're parsing
17 :polyglot # the polyglot name of what we're parsing
19 raise ArgumentError.new('Missing required args') unless (arg_keys - args.keys).empty?
21 polyglot = args[:polyglot].to_s
23 buffer = args[:buffer].to_s
25 language_breakdowns = Ohcount::parse(buffer, polyglot)
26 language_breakdowns.each do |lb|
27 lb_dest_dir = dir + "/" + lb.name
28 Dir.mkdir(lb_dest_dir)
30 File.open(lb_dest_dir + "/code", "w") do |io|
33 io.write "\n" unless (code.size == 0 || code[-1,1] == "\n")
37 File.open(lb_dest_dir + "/comment", "w") do |io|
40 io.write "\n" unless (comment.size == 0 || comment[-1,1] == "\n")
43 File.open(lb_dest_dir + "/blanks", "w") do |io|
44 io.write lb.blanks.to_s