officex2str 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Officex2str
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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(File.extname(file_path), archives)
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 extname, archives
15
- case extname
16
- when ".docx"
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 ".xlsx"
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 ".pptx"
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
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.add_development_dependency "rake", ["= 0.9.2"]
19
19
  gem.add_runtime_dependency "nokogiri", [">= 1.4.7"]
20
20
  gem.add_runtime_dependency "zipruby", ["= 0.3.6"]
21
+ gem.add_runtime_dependency "mime-types", [">= 1.17.2"]
21
22
 
22
23
  end
@@ -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, File.extname(@file_path), archives).sort
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
- #pages = Officex2str.pickup_pages(File.extname(@file_path), archives)
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
- - 2
9
- version: 0.0.2
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