Skip to content

Commit b3bc431

Browse files
dpskpythonicrubyist
authored andcommitted
add ability to fetch file from remote (#34)
1 parent 5c6c121 commit b3bc431

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

README.rdoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ Images for a specific cell can be obtained with images_at method:
7272

7373
Creek will most likely return nil for a cell with images if there is no other text cell in that row - you can use *images_at* method for retrieving images in that cell.
7474

75+
== Remote files
76+
77+
remote_url = 'http://dev-builds.libreoffice.org/tmp/test.xlsx'
78+
Creek::Book.new remote_url, remote: true
79+
7580
== Contributing
7681

7782
Contributions are welcomed. You can fork a repository, add your code changes to the forked branch, ensure all existing unit tests pass, create new unit tests cover your new changes and finally create a pull request.

lib/creek/book.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'zip/filesystem'
22
require 'nokogiri'
33
require 'date'
4+
require 'open-uri'
45

56
module Creek
67

@@ -19,6 +20,7 @@ def initialize path, options = {}
1920
extension = File.extname(options[:original_filename] || path).downcase
2021
raise 'Not a valid file format.' unless (['.xlsx', '.xlsm'].include? extension)
2122
end
23+
path = open(path) if options[:remote]
2224
@files = Zip::File.open path
2325
@shared_strings = SharedStrings.new(self)
2426
end

spec/test_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
open_book.should raise_error 'Not a valid file format.'
1616
end
1717

18+
it 'Fail to open remote file' do
19+
lambda { Creek::Book.new 'http://dev-builds.libreoffice.org/tmp/test.xlsx' }.should raise_error
20+
end
21+
22+
it 'Opens remote file with remote flag' do
23+
lambda { Creek::Book.new 'http://dev-builds.libreoffice.org/tmp/test.xlsx', remote: true }.should_not raise_error
24+
end
25+
1826
it 'Check file extension of original_filename if passed.' do
1927
path = 'spec/fixtures/temp_string_io_file_path_with_no_extension'
2028
lambda { Creek::Book.new path, :original_filename => 'invalid.xls' }.should raise_error 'Not a valid file format.'

0 commit comments

Comments
 (0)