class RamperFileMetrics
Constants
- CSV_COLS
self.method blows up unless it is after the functions are defined
- METRICS
Public Class Methods
new(flags)
click to toggle source
# File lib/ramper_file_metrics.rb, line 6 def initialize(flags) if flags.empty? selected = Array.new(CSV_COLS.count, true) else selected = Array.new(CSV_COLS.count, false) selected[0] = true #TODO: use command line parser #TODO: change array to hash flags.each do |f| case f when '-a' selected[3] = true when '-c' selected[2] = true when '-f' selected[4] = true when '-l' selected[1] = true end end end @csv_header = CSV_COLS.select.with_index { |_, ind| selected[ind] } @selected_metrics = METRICS.select.with_index { |_, ind| selected[ind] } end
Private Class Methods
flog_file(file)
click to toggle source
# File lib/ramper_file_metrics.rb, line 86 def self.flog_file(file) if /.*\.rb/.match(file) flogger = FlogCLI.new flogger.flog(file) flog_tot = flogger.total_score.round(2) flog_avg = flogger.average.round(2) [flog_tot, flog_avg] else Array.new(2, "N/A") end end
lines_of_code(file)
click to toggle source
# File lib/ramper_file_metrics.rb, line 57 def self.lines_of_code(file) `wc -l #{file}`.split(" ").first.strip end
start_end_dates_commits(file)
click to toggle source
# File lib/ramper_file_metrics.rb, line 48 def self.start_end_dates_commits(file) dates = `git log -- #{file} | grep 'Date: '`.split("\n") start_date = DateTime.parse(dates.last.strip.gsub(/Date: /, '')) end_date = DateTime.parse(dates.first.strip.gsub(/Date: /, '')) num_commits = dates.count [start_date, end_date, num_commits] end
Public Instance Methods
process_file(file)
click to toggle source
# File lib/ramper_file_metrics.rb, line 36 def process_file(file) @selected_metrics.map.with_index do |m, ind| begin m.call(file) rescue => e Array.new(@csv_header[ind].count, "Error #{e.message}".gsub(",", ";")) end end.flatten.join(', ') end
process_file_format()
click to toggle source
# File lib/ramper_file_metrics.rb, line 32 def process_file_format @csv_header.flatten.join(', ') end