class Dech::CSV

Constants

DEFAULT_ENCODING
HEADER_MAPPINGS
REQUIRED_HEADERS
STATIC_COLUMNS

Public Class Methods

new(array, args={}) click to toggle source
Calls superclass method
# File lib/dech/csv.rb, line 14
def initialize(array, args={})
  @array = array
  @option = {}
  @option[:headers]  = args[:headers] != false
  @option[:encoding] = args[:encoding] || DEFAULT_ENCODING
  super(csv_string)
end

Public Instance Methods

headers() click to toggle source
# File lib/dech/csv.rb, line 22
def headers
  @option[:headers] ? @array.first : nil
end
save_as(path) click to toggle source
# File lib/dech/csv.rb, line 26
def save_as(path)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, [:w, @option[:encoding].name].join(":")){|file| file << csv_string }
end
to_a() click to toggle source
# File lib/dech/csv.rb, line 31
def to_a
  @array
end
to_s() click to toggle source
# File lib/dech/csv.rb, line 35
def to_s
  csv_string
end

Private Instance Methods

csv_string() click to toggle source
# File lib/dech/csv.rb, line 41
def csv_string
  ::CSV.generate{|csv| @array.each{|row| csv << row } }.encode(@option[:encoding])
end