Sha256: 83dfaf355d933146bdf2683d7a852a4521441e8f17e47d941980d4ed6212f570
Contents?: true
Size: 876 Bytes
Versions: 1
Compression:
Stored size: 876 Bytes
Contents
require 'csv' require 'nkf' module Muzzy class Util def self.fetch_header_and_first_row(filepath, col_sep) raise ArgumentError, "filepath required" if filepath.nil? raise ArgumentError, "not found file" unless File.exists?(filepath) header_row, first_row = nil, nil from_fenc = 'UTF-8' File.open(filepath, "rt") do |f| s = f.readlines from_fenc = NKF.guess(s.join).to_s end open(filepath, "rb:#{from_fenc}:UTF-8", undef: :replace) do |f| CSV.new(f, col_sep: col_sep).each.with_index do |row, i| if i == 0 header_row = row elsif i == 1 first_row = row else break end end end return [header_row, first_row] rescue ArgumentError => e raise e rescue => e return [-1, -1] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
muzzy-0.1.14 | lib/muzzy/util.rb |