class Shoji::TextBase

Constants

ENCMAP

Public Class Methods

foreach(filename, opts = {}, &block) click to toggle source
# File lib/shoji/text_base.rb, line 12
def self.foreach(filename, opts = {}, &block)
  Shoji::UTF8File.convert filename do |path|
    limit = opts[:limit].to_i
    index = 0
    CSV.foreach(path, fastercsv_opts) do |row|
      block.call(row)
      index += 1
      break if (limit > 0 && limit <= index)
    end
  end
end
row_size(filename, opts = {}) click to toggle source
# File lib/shoji/text_base.rb, line 34
def self.row_size(filename, opts = {})
  enc = ENCMAP[Shoji::UTF8File.guess_encoding(filename)]
  index = 0
  CSV.foreach(filename, fastercsv_opts.merge({:encoding => enc})) do |row|
    index += 1
  end
  index
end
rows(filename, opts = {}) click to toggle source
# File lib/shoji/text_base.rb, line 27
def self.rows(filename, opts = {})
  rows = []
  self.foreach(filename, opts) do |row|
    rows << row
  end
  rows
end
valid_file?(filename, opts = {}) click to toggle source
# File lib/shoji/text_base.rb, line 23
def self.valid_file?(filename, opts = {})
  Shoji::UTF8File.convert filename do |path|
  end
end

Protected Class Methods

fastercsv_opts() click to toggle source
# File lib/shoji/text_base.rb, line 43
def self.fastercsv_opts; raise NoMethodError.new; end
first_line(filename) click to toggle source
# File lib/shoji/text_base.rb, line 44
def self.first_line(filename)
  line = nil
  Shoji::UTF8File.convert filename do |path|
    File.foreach(path) do |l|
      line = l
      break
    end
  end
  line
end
has_char?(filename, char) click to toggle source
# File lib/shoji/text_base.rb, line 54
def self.has_char?(filename, char)
  first_line(filename).include? char
end