Sha256: 68a77bd11eaa8aed9d7c55d16171466b849d4f071ae95fd6c5702955c1c492da
Contents?: true
Size: 880 Bytes
Versions: 5
Compression:
Stored size: 880 Bytes
Contents
# coding: utf-8 require 'csv' require 'stringio' module Dech class CSV < StringIO DEFAULT_ENCODING = Encoding::Windows_31J HEADER_MAPPINGS = {} REQUIRED_HEADERS = [] STATIC_COLUMNS = {} 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
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
dech-0.1.1 | lib/dech/csv.rb |
dech-0.1.0 | lib/dech/csv.rb |
dech-0.0.7 | lib/dech/csv.rb |
dech-0.0.6 | lib/dech/csv.rb |
dech-0.0.5 | lib/dech/csv.rb |