Class: Tap::Tasks::Load::Csv

Inherits:
Tap::Tasks::Load show all
Defined in:
lib/tap/tasks/load/csv.rb

Overview

:startdoc::task reads csv data

Load CSV data as an array of arrays, selecting the specified rows and columns.

% tap load/csv 'a,b,c.d,e,f' --row-sep '.' -: inspect
[["a", "b", "c"], ["d", "e", "f"]]

Note this task is quite inefficient in that it will load all data before making a selection; large files or edge selections may benefit from an alternate task.

Instance Method Summary collapse

Instance Method Details

#load(io) ⇒ Object

Loads the io data as CSV, into an array of arrays.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tap/tasks/load/csv.rb', line 29

def load(io)
  data = parse(io.read)
  
  if rows
    data = data[rows]
  end
  
  if columns
    data.collect! do |cols|
      cols[columns]
    end
  end
  
  data
end