Module: XlsParser

Included in:
Builder, Populator
Defined in:
lib/vardb/xls_parser.rb

Class Method Summary collapse

Class Method Details

.load_meta_fields(file) ⇒ Object

A few rules about Excel files:

  1. .xls only, this can’t accept .xlsx

  2. There should be no empty cells in the header row of a sheet (first row)

  3. For good form, there shouldn’t be any subsequent rows that are longer than the header row

  4. There should not be any duplicate cell names in the header row



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vardb/xls_parser.rb', line 10

def XlsParser.load_meta_fields(file)
  s = Roo::Excel.new(file)
  s.default_sheet = s.sheets.first

  columns = 1
  until s.cell(1, columns).nil?
    columns += 1
  end

  counter = 1

   = []

  columns.times do |counter|
      if s.cell(1, counter).nil?
        << ", empty#{counter}"
      else 
           << ", #{s.cell(1, counter).to_s.gsub(/\s+/, "").gsub("-","").gsub("(","").gsub(")","").gsub(".","").gsub("/","")}"
      end
      counter += 1
  end

  return 
end