Class: Mnemonic::Sink::CSV
- Inherits:
-
Object
- Object
- Mnemonic::Sink::CSV
- Defined in:
- lib/mnemonic/sink/csv.rb
Instance Method Summary collapse
- #close ⇒ Object
- #drop!(extra) ⇒ Object
-
#initialize(mnemonic, to = STDOUT, options = {}) ⇒ CSV
constructor
A new instance of CSV.
Constructor Details
#initialize(mnemonic, to = STDOUT, options = {}) ⇒ CSV
Returns a new instance of CSV.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mnemonic/sink/csv.rb', line 6 def initialize(mnemonic, to = STDOUT, = {}) @mnemonic = mnemonic col_count = mnemonic.metrics.length headers = mnemonic.metric_names @extra_column = .delete(:extra) if @extra_column col_count += 1 headers = headers.dup << 'Extra'.freeze end [:headers] = headers [:write_headers] = true @io = if to.kind_of? String @need_close = true File.open(to, 'w') else to end @csv = ::CSV.new(@io, ) @row = Array.new(col_count) end |
Instance Method Details
#close ⇒ Object
38 39 40 |
# File 'lib/mnemonic/sink/csv.rb', line 38 def close @io.close if @need_close end |
#drop!(extra) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/mnemonic/sink/csv.rb', line 30 def drop!(extra) @mnemonic.metrics.each_with_index do |metric, i| @row[i] = metric.value end @row[-1] = extra if @extra_column @csv << @row end |