Class: MergeExcel::SpreadsheetParser

Inherits:
Object
  • Object
show all
Extended by:
FormatDetector
Defined in:
lib/merge_excel/spreadsheet_parser.rb

Class Method Summary collapse

Methods included from FormatDetector

detect_format

Class Method Details

.open(filepath) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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