diff options
| author | 2017-06-12 03:37:11 -0400 | |
|---|---|---|
| committer | 2017-06-12 03:37:11 -0400 | |
| commit | 8280a21a23d44aa90177e2bc041d0b8dc8556f4b (patch) | |
| tree | dadef7ee085c0e990a5070bd41b6a5b98c97f4fd /lib/roo/spreadsheet.rb | |
Import Upstream version 2.7.1upstream/2.7.1
Diffstat (limited to 'lib/roo/spreadsheet.rb')
| -rw-r--r-- | lib/roo/spreadsheet.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/roo/spreadsheet.rb b/lib/roo/spreadsheet.rb new file mode 100644 index 0000000..1eef58d --- /dev/null +++ b/lib/roo/spreadsheet.rb @@ -0,0 +1,33 @@ +require 'uri' + +module Roo + class Spreadsheet + class << self + def open(path, options = {}) + path = path.respond_to?(:path) ? path.path : path + extension = extension_for(path, options) + + begin + Roo::CLASS_FOR_EXTENSION.fetch(extension).new(path, options) + rescue KeyError + raise ArgumentError, + "Can't detect the type of #{path} - please use the :extension option to declare its type." + end + end + + def extension_for(path, options) + case (extension = options.delete(:extension)) + when ::Symbol + options[:file_warning] = :ignore + extension + when ::String + options[:file_warning] = :ignore + extension.tr('.', '').downcase.to_sym + else + res = ::File.extname((path =~ /\A#{::URI.regexp}\z/) ? ::URI.parse(::URI.encode(path)).path : path) + res.tr('.', '').downcase.to_sym + end + end + end + end +end |
