Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc2text.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'doc2text'
s.version = '0.4.10'
s.version = '0.4.11'
s.authors = 'Valentin A.'
s.email = 'valentin@nalisbg.com'
s.homepage = 'http://doc2text.com'
Expand Down
8 changes: 4 additions & 4 deletions lib/doc2text/xml_based_document_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def unpack
|zip_file|
Dir.mkdir(extract_path)
zip_file.each do |entry|
zipped_file_extract_path = File.join extract_path, entry.name
FileUtils.mkdir_p File.dirname(zipped_file_extract_path)
zip_file.extract entry, zipped_file_extract_path
zipped_file_extract_path = File.join extract_path, File.dirname(entry.name)
FileUtils.mkdir_p zipped_file_extract_path
zip_file.extract entry, nil, destination_directory: extract_path
end
}
end
Expand All @@ -41,7 +41,7 @@ def extract_extension
end

def extract_path
File.join File.dirname(@document_path), ".#{File.basename(@document_path)}_#{extract_extension}"
@extract_path ||= File.join File.dirname(@document_path), ".#{File.basename(@document_path)}_#{extract_extension}"
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions spec/unpack_odt_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'tempfile'

describe 'odt' do
def rspec_extract_odt
Expand All @@ -17,4 +18,24 @@ def rspec_extract_odt
rspec_extract_odt
rspec_extract_odt
end

context "when the odt is a temporary file" do
it "runs from a temp file" do
tempfile = Tempfile.new('text_styles.odt')
tempfile.write File.read(File.join 'spec', 'fixtures', 'text_styles.odt')
tempfile.rewind
tempfile.close

@odt = Doc2Text::Odt::Document.new tempfile
@odt.unpack

entries = Dir.glob "#{@odt.extract_path}/**/*"
mandatory_files = %w(manifest.rdf content.xml settings.xml styles.xml META-INF META-INF/manifest.xml meta.xml mimetype).map { |entry|
File.join @odt.extract_path, entry }
expect(mandatory_files.to_set).to be_subset(entries.to_set)

tempfile.unlink
@odt.clean
end
end
end
Loading