Class: Dech::CSV

Inherits:
StringIO
  • Object
show all
Defined in:
lib/dech/csv.rb

Direct Known Subclasses

Dena::CSV, Ponpare::CSV, Rakuten::CSV, Yahoo::CSV

Constant Summary collapse

DEFAULT_ENCODING =
Encoding::Windows_31J
HEADER_MAPPINGS =
{}
REQUIRED_HEADERS =
[]
STATIC_COLUMNS =
{}

Instance Method Summary collapse

Constructor Details

#initialize(array, args = {}) ⇒ CSV

Returns a new instance of CSV.



14
15
16
17
18
19
20
# 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

Instance Method Details

#headersObject



22
23
24
# File 'lib/dech/csv.rb', line 22

def headers
  @option[:headers] ? @array.first : nil
end

#save_as(path) ⇒ Object



26
27
28
29
# 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_aObject



31
32
33
# File 'lib/dech/csv.rb', line 31

def to_a
  @array
end

#to_sObject



35
36
37
# File 'lib/dech/csv.rb', line 35

def to_s
  csv_string
end