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
|
# File 'lib/loader_txt.rb', line 4
def self.makeMatrix(file, opts={:sep=>"\t", :offset=>0})
out = []
epath = encodePath(file)
if(!File.exist?(epath))
open(epath, 'w') do |fo|
fo.print("\n\n")
end
end
path = self.encodePath(file)
fi = open(path, "r:Windows-31J")
if(opts[:offset])
opts[:offset].times do |i|
fi.gets
end
end
opts[:sep]||="\t"
fi.each do |line|
row = MyMatrix.toutf8(line).chomp.split(/#{opts[:sep]}/)
newRow = []
row.each do |cell|
stri = cell.dup
stri.gsub!(/^\"(.*)\"$/, '\1')
stri.gsub!(/""/, '"')
newRow << stri
end
out << newRow
end
fi.close
return out
end
|