-
Notifications
You must be signed in to change notification settings - Fork 500
/
spreadsheet.rb
35 lines (33 loc) · 993 Bytes
/
spreadsheet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Roo
class Spreadsheet
class << self
def open(file, options = {})
file = file.respond_to?(:path) ? file.path : file
extension =
if options[:extension]
options[:file_warning] = :ignore
".#{options.delete(:extension)}".gsub(/[.]+/, ".")
else
File.extname(URI.decode(URI.parse(URI.encode(file)).path))
end
case extension.downcase
when '.xls'
Roo::Excel.new(file, options)
when '.xlsx'
Roo::Excelx.new(file, options)
when '.ods'
Roo::OpenOffice.new(file, options)
when '.xml'
Roo::Excel2003XML.new(file, options)
when ''
Roo::Google.new(file, options)
when '.csv'
Roo::CSV.new(file, options)
else
raise ArgumentError,
"Can't detect the type of #{file} - please use the :extension option to declare its type."
end
end
end
end
end