Skip to content

Commit

Permalink
Handle opening https:// uris along with http://
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed Sep 20, 2012
1 parent 227e880 commit fc5c589
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/roo/excel.rb
Expand Up @@ -19,7 +19,7 @@ class Roo::Excel < Roo::GenericSpreadsheet
def initialize(filename, packed = nil, file_warning = :error)
file_type_check(filename,'.xls','an Excel', file_warning, packed)
make_tmpdir do |tmpdir|
filename = open_from_uri(filename, tmpdir) if filename[0,7] == "http://"
filename = open_from_uri(filename, tmpdir) if uri?(filename)
filename = open_from_stream(filename[7..-1], tmpdir) if filename[0,7] == "stream:"
filename = unzip(filename, tmpdir) if packed == :zip

Expand Down
2 changes: 1 addition & 1 deletion lib/roo/excel2003xml.rb
Expand Up @@ -10,7 +10,7 @@ class Roo::Excel2003XML < Roo::GenericSpreadsheet
# values for packed: :zip
def initialize(filename, packed=nil, file_warning=:error)
make_tmpdir do |tmpdir|
filename = open_from_uri(filename, tmpdir) if filename[0,7] == "http://"
filename = open_from_uri(filename, tmpdir) if uri?(filename)
filename = unzip(filename, tmpdir) if packed == :zip

file_type_check(filename,'.xml','an Excel 2003 XML', file_warning)
Expand Down
2 changes: 1 addition & 1 deletion lib/roo/excelx.rb
Expand Up @@ -87,7 +87,7 @@ class Roo::Excelx < Roo::GenericSpreadsheet
def initialize(filename, packed=nil, file_warning = :error) #, create = false)
file_type_check(filename,'.xlsx','an Excel-xlsx', file_warning, packed)
make_tmpdir do |tmpdir|
filename = open_from_uri(filename, tmpdir) if filename[0,7] == "http://"
filename = open_from_uri(filename, tmpdir) if uri?(filename)
filename = unzip(filename, tmpdir) if packed == :zip
@cells_read = Hash.new
@filename = filename
Expand Down
4 changes: 4 additions & 0 deletions lib/roo/generic_spreadsheet.rb
Expand Up @@ -626,6 +626,10 @@ def normalize(row,col)
return row,col
end

def uri?(filename)
filename.start_with?("http://", "https://")
end

def open_from_uri(uri, tmpdir)
require 'open-uri'
response = ''
Expand Down
2 changes: 1 addition & 1 deletion lib/roo/openoffice.rb
Expand Up @@ -37,7 +37,7 @@ def process_zipfile(tmpdir, zip, path='')
def initialize(filename, packed=nil, file_warning=:error, tmpdir_root=nil)
file_type_check(filename,'.ods','an Roo::Openoffice', file_warning, packed)
make_tmpdir(tmpdir_root) do |tmpdir|
filename = open_from_uri(filename, tmpdir) if filename[0,7] == "http://"
filename = open_from_uri(filename, tmpdir) if uri?(filename)
filename = unzip(filename, tmpdir) if packed == :zip
@cells_read = Hash.new
#TODO: @cells_read[:default] = false
Expand Down

0 comments on commit fc5c589

Please sign in to comment.