class Bmg::Reader::Excel

Constants

DEFAULT_OPTIONS

Public Class Methods

new(type, path, options = {}) click to toggle source
# File lib/bmg/reader/excel.rb, line 11
def initialize(type, path, options = {})
  @type = type
  @path = path
  @options = DEFAULT_OPTIONS.merge(options)
end

Public Instance Methods

each() { |tuple| ... } click to toggle source
# File lib/bmg/reader/excel.rb, line 17
def each
  return to_enum unless block_given?
  require 'roo'
  xlsx = Roo::Spreadsheet.open(@path, @options)
  headers = nil
  xlsx.sheet(0)
    .each
    .drop(@options[:skip])
    .each_with_index
    .each do |row, i|
      if i==0
        headers = row.map{|c| c.to_s.strip.to_sym }
      else
        init = init_tuple(i)
        tuple = (0...headers.size)
          .each_with_object(init){|i,t|
            t[headers[i]] = row[i]
          }
        yield(tuple)
      end
    end
end
inspect()
Alias for: to_s
to_ast() click to toggle source
# File lib/bmg/reader/excel.rb, line 40
def to_ast
  [ :excel, @path, @options ]
end
to_s() click to toggle source
# File lib/bmg/reader/excel.rb, line 44
def to_s
  "(excel #{@path})"
end
Also aliased as: inspect

Private Instance Methods

init_tuple(i) click to toggle source
# File lib/bmg/reader/excel.rb, line 51
def init_tuple(i)
  case as = @options[:row_num]
  when TrueClass
    { :row_num => i }
  when FalseClass
    {}
  when Symbol
    { :"#{as}" => i }
  end
end