4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/loader_csv.rb', line 4
def self.makeMatrix(file, opts={:offset=>0})
if(RUBY_VERSION =~ /1\.[^9]/)
require 'fastercsv'
csv = FasterCSV
else
require 'csv'
Encoding.default_external = 'Windows-31J'
csv = CSV
end
out = []
i= 0
syspath = self.encodePath(file)
csv.foreach(syspath, {:row_sep => "\r\n", :encoding => 'Shift_JIS'}) do |row|
if(opts[:offset])
if(opts[:offset] < i)
next
end
end
newRow = []
row.each do |cell|
cell = cell.to_s
cell ||= ''
cell = MyMatrix.toutf8(cell)
newRow << cell
end
out << newRow
i += 1
end
return out
end
|