officex2str 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/officex2str/version.rb +1 -1
- data/lib/officex2str.rb +7 -6
- data/officex2str.gemspec +1 -0
- data/spec/officex2str_spec.rb +2 -3
- metadata +17 -2
data/lib/officex2str/version.rb
CHANGED
data/lib/officex2str.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'zipruby'
|
3
|
+
require 'mime/types'
|
3
4
|
#require "officex2str/version"
|
4
5
|
|
5
6
|
module Officex2str
|
6
7
|
def self.convert(file_path)
|
7
8
|
archives = Zip::Archive.open(file_path) { |archive| archive.map(&:name) }
|
8
|
-
pages = self.pickup_pages(
|
9
|
+
pages = self.pickup_pages(file_path, archives)
|
9
10
|
xmls = self.extract_xmls(file_path, pages)
|
10
11
|
self.xml_to_str(xmls)
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
|
-
def self.pickup_pages
|
15
|
-
case
|
16
|
-
when ".
|
15
|
+
def self.pickup_pages file_path, archives
|
16
|
+
case content_type = MIME::Types.type_for(file_path).first.content_type
|
17
|
+
when "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
17
18
|
archives.select{|a| /^word\/document/ =~ a}
|
18
|
-
when ".
|
19
|
+
when "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
19
20
|
archives.select{|a| /^xl\/worksheets\/sheet/ =~ a or /^xl\/sharedStrings/ =~ a or /^xl\/comments/ =~ a }
|
20
|
-
when ".
|
21
|
+
when "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
21
22
|
archives.select{|a| /^ppt\/slides\/slide/ =~ a}
|
22
23
|
else
|
23
24
|
nil
|
data/officex2str.gemspec
CHANGED
data/spec/officex2str_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Officex2str do
|
|
5
5
|
context "#pickup_pages" do
|
6
6
|
subject do
|
7
7
|
archives = Zip::Archive.open(@file_path) { |archive| archive.map(&:name) }
|
8
|
-
Officex2str.send(:pickup_pages,
|
8
|
+
Officex2str.send(:pickup_pages, @file_path, archives).sort
|
9
9
|
end
|
10
10
|
context "extname is docx" do
|
11
11
|
before do
|
@@ -32,8 +32,7 @@ describe Officex2str do
|
|
32
32
|
context "#convert" do
|
33
33
|
subject do
|
34
34
|
archives = Zip::Archive.open(@file_path) { |archive| archive.map(&:name) }
|
35
|
-
|
36
|
-
pages = Officex2str.send(:pickup_pages, File.extname(@file_path), archives)
|
35
|
+
pages = Officex2str.send(:pickup_pages, @file_path, archives)
|
37
36
|
xmls = Officex2str.send(:extract_xmls, @file_path, pages)
|
38
37
|
Officex2str.convert(@file_path)
|
39
38
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- interu
|
@@ -62,6 +62,21 @@ dependencies:
|
|
62
62
|
version: 0.3.6
|
63
63
|
type: :runtime
|
64
64
|
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: mime-types
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 17
|
76
|
+
- 2
|
77
|
+
version: 1.17.2
|
78
|
+
type: :runtime
|
79
|
+
version_requirements: *id004
|
65
80
|
description: convert office 2010 files to str
|
66
81
|
email:
|
67
82
|
- interu@sonicgarden.jp
|