Module: BAMFCSV

Defined in:
lib/bamfcsv.rb,
lib/bamfcsv/table.rb,
lib/bamfcsv/version.rb,
ext/bamfcsv/bamfcsv_ext.c

Defined Under Namespace

Classes: InvalidSeparator, MalformedCSVError, Table

Constant Summary collapse

VERSION =
"0.3.2"

Class Method Summary collapse

Class Method Details

.parse(csv_str, opts = {}) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bamfcsv.rb', line 10

def self.parse(csv_str, opts={})
  return [] if csv_str.empty?
  # We need to do this because the C extension currently overwrites
  # the input, and all of String#clone, String#dup, and String.new
  # copy the pointer, not the contents. So we make a copy, parse
  # that, and throw away the copy.
  copy = "" + csv_str
  separator = opts.fetch(:separator, ',')
  raise InvalidSeparator, "Separator must be exactly one character long" if separator.size != 1
  raise InvalidSeparator, "Separator cannot be '\"'" if separator == '"'
  matrix = __parse_string(copy, separator)
  if opts[:headers]
    Table.new(matrix)
  else
    matrix
  end
end

.read(thing_to_read, opts = {}) ⇒ Object



6
7
8
# File 'lib/bamfcsv.rb', line 6

def self.read(thing_to_read, opts={})
  parse(File.read(thing_to_read), opts)
end