Class: Reader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/csv_combine.rb

Instance Method Summary collapse

Constructor Details

#initialize(files, opt) ⇒ Reader

Returns a new instance of Reader.



25
26
27
28
# File 'lib/csv_combine.rb', line 25

def initialize(files,opt)
  @files = files
  @opt = opt
end

Instance Method Details

#eachObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/csv_combine.rb', line 30

def each
  hash_list = []
  @files.each do |file|
    reader = CSV.open(file,"r")
    reader.shift if @opt[:skip_header_files].class == Array && @opt[:skip_header_files].index(file)
    reader.shift if @opt[:skip_header_files] == file
    reader.each do |row|
      if @opt[:uniq]
        hash = Digest::SHA1.new.update(row.to_s).to_s
        yield row unless hash_list.index(hash)
        hash_list << hash
      else
        yield row
      end
    end
  end
end