Class: Dech::CSV
- Inherits:
-
StringIO
- Object
- StringIO
- Dech::CSV
show all
- Defined in:
- lib/dech/csv.rb
Constant Summary
collapse
- DEFAULT_ENCODING =
Encoding::Windows_31J
{}
[]
- 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
22
23
24
|
# File 'lib/dech/csv.rb', line 22
def
@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_a ⇒ Object
31
32
33
|
# File 'lib/dech/csv.rb', line 31
def to_a
@array
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/dech/csv.rb', line 35
def to_s
csv_string
end
|