Class: LoaderTxt

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

Class Method Summary collapse

Methods inherited from FileIO

encodePath, filesystem

Class Method Details

.makeMatrix(file, opts = {:sep=>"\t", :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
# File 'lib/loader_txt.rb', line 4

def self.makeMatrix(file, opts={:sep=>"\t", :offset=>0})
#TSV: tab separated value 読み込みメソッド

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]}/)
	#「1,300台」などカンマが使われている場合、「"1,300台"」となってしまうので、カンマを無視する
	newRow = []
	row.each do |cell|
		stri = cell.dup
		stri.gsub!(/^\"(.*)\"$/, '\1')
		#"
		stri.gsub!(/""/, '"')
		newRow << stri
	end
	out << newRow
end
fi.close
return out


end