Last active
May 31, 2021 17:20
-
-
Save alexblackie/6e69f3d77af98747a44bc5920b9f4115 to your computer and use it in GitHub Desktop.
cloc stats per directory
This file contains 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
require 'csv' | |
require 'json' | |
# Generate stats.csv with `cloc`: | |
# | |
# cloc --csv --by-file --report-file stats.csv . | |
# CSV row: | |
# language,filename,blank,comment,code,version | |
csv = CSV.new(File.read('stats.csv')).read | |
stats = csv.reduce({}) do |acc, row| | |
next acc if row[1] == nil | |
lang = row[0] | |
folder = row[1].split('/')[1] | |
next acc unless File.directory?(folder) | |
acc[folder] ||= {} | |
acc[folder][lang] ||= 0 | |
acc[folder][lang] += row[4].to_i | |
acc | |
end | |
puts JSON.generate(stats) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment