Class: LoaderTxt
Class Method Summary collapse
Methods inherited from FileIO
encodePath, filesystem, readPath
Class Method Details
.makeMatrix(file, opts = nil) ⇒ 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_txt.rb', line 4 def self.makeMatrix(file, opts=nil) #TSV: tab separated value 読み込みメソッド opts ||= {} opts[:sep] ||= "\t" opts[:offset] ||= 0 opts[:encode] ||= "Windows-31J" 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:#{opts[:encode]}") 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 |