class Anamo::Fstree::Writer

Public Class Methods

new(path = '.', prefix = nil, base_path = '/') click to toggle source
# File lib/anamo/fstree/thor.rb, line 13
def initialize path = '.', prefix = nil, base_path = '/'
  @row_count = 0
  @previous_row = nil
  @handle = nil
  @files_per_file = 1000000
  @path = path
  @prefix = prefix
  @base_path = base_path
  init_handle
end

Public Instance Methods

add_row(row) click to toggle source
# File lib/anamo/fstree/thor.rb, line 39
def add_row row
  reinit_handle if @row_count > 0 && @row_count % @files_per_file == 0
  [0,2,3,4,5].each { |i| row[i] = '' if @previous_row[i] == row[i] } if @previous_row
  @handle.write row.to_csv
  @row_count = @row_count + 1
  @previous_row = row
end
close() click to toggle source
# File lib/anamo/fstree/thor.rb, line 47
def close
  @handle.close
end
close_handle() click to toggle source
# File lib/anamo/fstree/thor.rb, line 29
def close_handle
  @handle.close if @handle
end
init_handle() click to toggle source
# File lib/anamo/fstree/thor.rb, line 24
def init_handle
  @handle = Zlib::GzipWriter.open("#{@path}/#{@prefix ? "#{@prefix}-" : ""}#{(@row_count/@files_per_file).round}.gz")
  @handle.write "[#{@base_path}]\n"
end
reinit_handle() click to toggle source
# File lib/anamo/fstree/thor.rb, line 33
def reinit_handle
  close_handle
  GC.start
  init_handle
end