class MergeExcel::SpreadsheetParser

Public Class Methods

open(filepath) click to toggle source
# File lib/merge_excel/spreadsheet_parser.rb, line 5
def self.open(filepath)
  extname = detect_format(filepath)
  case extname
  when :xls
    book = Spreadsheet.open(filepath)
  when :xlsx
    book = RubyXL::Parser.parse(filepath)
  end
  book.instance_variable_set(:@extname, extname)
  book.instance_variable_set(:@filename, File.basename(filepath))

  def book.xls?
    @extname==:xls ? true : false
  end
  def book.xlsx?
    !book.xls?
  end
  def book.filename
    @filename
  end
  book
end