4 # Parses a file, and store the results in files on disk.
6 # This method primarily exists for the benefit of the Ohloh analysis engine,
7 # which prefers to store interim results in files on disk. It is unlikely to be
8 # useful to the general public.
10 # A subdirectory is created for each language found in the target file.
11 # Within each language subdirectory, separate files are created for code, comments, and blanks.
13 # The 'code' file contains code lines, the 'comments' file contains comment lines, and the 'blanks'
14 # file contains a count of the number of blank lines in the file.
15 def self.parse_to_dir(args)
17 :dir, # directory to parse to
18 :buffer, # buffer contents of the what we're parsing
19 :polyglot # the polyglot name of what we're parsing
21 raise ArgumentError.new('Missing required args') unless (required_arg_keys - args.keys).empty?
23 polyglot = args[:polyglot].to_s
25 buffer = args[:buffer].to_s
26 find_licenses = args[:find_licenses].to_s
29 Ohcount::parse(buffer, polyglot).each do |lb|
30 lb_dest_dir = dir + "/" + lb.name
31 Dir.mkdir(lb_dest_dir)
33 File.open(lb_dest_dir + "/code", "w") do |io|
36 io.write "\n" unless (code.size == 0 || code[-1,1] == "\n")
40 File.open(lb_dest_dir + "/comment", "w") do |io|
43 io.write "\n" unless (comment.size == 0 || comment[-1,1] == "\n")
46 # find licenses if required
47 licenses += LicenseSniffer.sniff(lb.comment) if find_licenses
49 File.open(lb_dest_dir + "/blanks", "w") do |io|
50 io.write lb.blanks.to_s
56 File.open(dir + "/licenses.yaml", "w") do |io|
57 io.write licenses.to_yaml