Class: DataImp::Parser::Spreadsheet

Inherits:
DataImp::Parser show all
Defined in:
lib/data_imp/parser/spreadsheet.rb

Direct Known Subclasses

Ods, Xls, Xlsx

Instance Attribute Summary

Attributes inherited from DataImp::Parser

#filename

Instance Method Summary collapse

Methods inherited from DataImp::Parser

find_parser, #initialize, #parse

Constructor Details

This class inherits a constructor from DataImp::Parser

Instance Method Details

#optionsObject



3
4
5
# File 'lib/data_imp/parser/spreadsheet.rb', line 3

def options
  { }
end

#process(input, &block) ⇒ Object



17
18
19
# File 'lib/data_imp/parser/spreadsheet.rb', line 17

def process input, &block
  raise "unable to process spreadsheet as a stream"
end

#process_file(&block) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/data_imp/parser/spreadsheet.rb', line 7

def process_file &block
  spreadsheet = Roo::Spreadsheet.open(filename, options)
  header = spreadsheet.row(1)
  (2..spreadsheet.last_row).each do |index|
    row = spreadsheet.row(index)
    hash = [header, row].transpose.to_h
    yield hash, index
  end
end