Sha256: 5d4ea3d62e793fdb385c3a874f7dd09c5b71fa225b89c311fbace229370fa89d
Contents?: true
Size: 801 Bytes
Versions: 1
Compression:
Stored size: 801 Bytes
Contents
# coding: utf-8 require 'csv' require 'stringio' module Dech class CSV < StringIO DEFAULT_ENCODING = Encoding::Windows_31J def initialize(array, args={}) @array = array @option = {} @option[:headers] = args[:headers] != false @option[:encoding] = args[:encoding] || DEFAULT_ENCODING super(csv_string) end def headers @option[:headers] ? @array.first : nil end def save_as(path) FileUtils.mkdir_p(File.dirname(path)) File.open(path, [:w, @option[:encoding].name].join(":")){|file| file << csv_string } end def to_a @array end def to_s csv_string end private def csv_string ::CSV.generate{|csv| @array.each{|row| csv << row } }.encode(@option[:encoding]) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dech-0.0.4 | lib/dech/csv.rb |