Sha256: c01071ff5786964ee3f86c017dae59c9103e3dedafb06d3a5363d10f81a3920d

Contents?: true

Size: 954 Bytes

Versions: 6

Compression:

Stored size: 954 Bytes

Contents

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 =~ ::URI.regexp) ? ::URI.parse(::URI.encode(path)).path : path)
          res.tr('.', '').downcase.to_sym
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
roo-2.0.1 lib/roo/spreadsheet.rb
culturecode-roo-2.0.2 lib/roo/spreadsheet.rb
culturecode-roo-2.0.1 lib/roo/spreadsheet.rb
roo-2.0.0 lib/roo/spreadsheet.rb
roo-2.0.0beta1 lib/roo/spreadsheet.rb
roo-andyw8-2.0.0 lib/roo/spreadsheet.rb