Class: RamperFileMetrics
- Inherits:
-
Object
- Object
- RamperFileMetrics
- Defined in:
- lib/ramper_file_metrics.rb
Instance Method Summary collapse
-
#initialize(flags) ⇒ RamperFileMetrics
constructor
A new instance of RamperFileMetrics.
- #process_file(file) ⇒ Object
- #process_file_format ⇒ Object
Constructor Details
#initialize(flags) ⇒ RamperFileMetrics
Returns a new instance of RamperFileMetrics.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ramper_file_metrics.rb', line 5 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 |
Instance Method Details
#process_file(file) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/ramper_file_metrics.rb', line 35 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 ⇒ Object
31 32 33 |
# File 'lib/ramper_file_metrics.rb', line 31 def process_file_format @csv_header.flatten.join(', ') end |