class CArray

Public Class Methods

from_csv(io, sep: ",", rs: $/, &block) click to toggle source
# File lib/carray-io-csv/core.bak.rb, line 552
def self.from_csv (io, sep: ",", rs: $/, &block)
  reader = CA::CSVReader.new(sep: sep, rs: rs, &block)
  case io
  when IO, StringIO
    return reader.read_io(io)
  when String
    return reader.read_string(io)
  else
    raise "invalid argument"
  end
end
load_csv(file, sep: ",", rs: $/, encoding: nil, &block) click to toggle source
# File lib/carray-io-csv/core.bak.rb, line 547
def self.load_csv (file, sep: ",", rs: $/, encoding: nil, &block)
  reader = CA::CSVReader.new(sep: sep, rs: rs, &block)
  return reader.read_file(file, encoding: encoding)
end
parse_csv(io, sep: ",", rs: $/, quote_char: '"', &block) click to toggle source
# File lib/carray-io-csv/core.rb, line 528
def self.parse_csv (io, sep: ",", rs: $/, quote_char: '"', &block)
  reader = CA::CSVReader.new(sep: sep, rs: rs, quote_char: quote_char, &block)
  case io
  when IO, StringIO
    return reader.read_io(io)
  when String
    return reader.read_string(io)
  else
    raise "invalid argument"
  end
end
read_csv(file, sep: ",", rs: $/, quote_char: '"', encoding: nil, &block) click to toggle source
# File lib/carray-io-csv/core.rb, line 517
def self.read_csv (file, sep: ",", rs: $/, quote_char: '"', encoding: nil, &block)
  reader = CA::CSVReader.new(sep: sep, rs: rs, quote_char: quote_char, &block)
  return reader.read_file(file, encoding: encoding)
end

Public Instance Methods

save_csv(file, rs: $/, sep: ",", fill: "", mode: "w", &block) click to toggle source
# File lib/carray-io-csv/core.bak.rb, line 564
def save_csv (file, rs: $/, sep: ",", fill: "", mode: "w", &block)
  writer = CA::CSVWriter.new(sep, rs, fill, &block)
  return writer.write_file(self, file, mode)
end
to_csv(io="", rs: $/, sep: ",", fill: "", &block) click to toggle source
# File lib/carray-io-csv/core.bak.rb, line 569
def to_csv (io="", rs: $/, sep: ",", fill: "", &block)
  writer = CA::CSVWriter.new(sep, rs, fill, &block)
  case io
  when IO, StringIO
    return writer.write_io(self, io)
  when String
    return writer.write_string(self, io)
  end
end
to_tabular(**option) click to toggle source
# File lib/carray-io-csv/core.bak.rb, line 579
def to_tabular (**option)
  option = {:sep=>" ", :names=>nil}.update(option)
  if option[:names]
    names = option[:names]
  elsif self.respond_to?(:names)
    names = self.names
  end
  sep = option[:sep]
  data = self.to_ca.map! {|s| s.to_s }
  table  = CArray.join([names.to_ca], [data])
  length = table.convert{|s| s.length}.max(0)
  table.map_with_index! {|s, idx| s.rjust(length[idx[1]]) }.to_csv.gsub(/,/,sep)
end