Class: LoaderCsv

Inherits:
FileIO show all
Defined in:
lib/loader_csv.rb

Class Method Summary collapse

Methods inherited from FileIO

encodePath, filesystem

Class Method Details

.makeMatrix(file, opts = {:offset=>0}) ⇒ Object



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})
#CSV読み込みメソッド
#1.9系ではFasterCSVを使えない
if(RUBY_VERSION =~ /1\.[^9]/)
	#1.8以下の場合
	require 'fastercsv'
	csv = FasterCSV
else
	#1.9以上の場合
	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
	#「1,300台」などカンマが使われている場合、「"1,300台"」となってしまうので、カンマを無視する
	newRow = []
	row.each do |cell|
		cell = cell.to_s
		cell ||= ''
		cell = MyMatrix.toutf8(cell)
		#cell = cell.gsub(/^\"/, "")
		#cell = cell.gsub(/\"$/, "")
		#"
		newRow << cell
	end
	out << newRow
	i += 1
end
return out


end