yomu 0.1.10 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +2 -1
- data/lib/yomu.rb +26 -17
- data/lib/yomu/version.rb +1 -1
- data/spec/yomu_spec.rb +10 -8
- data/yomu.gemspec +10 -9
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef1ce415813b44ff2a36e29a49b59768dd72f7f3
|
4
|
+
data.tar.gz: 17c69e97c25e156d101e6cef2c5b3f1fb149190d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ad3d4a04d785d0a31028f91d196d797d98e93f9289693d53987f9f72086c6e1c2a86057bc54055e2eb5db87324d370229cb92e8d2bc1ccccf8ecc09a8764f44
|
7
|
+
data.tar.gz: f1e70048c8c42b9750e14bb0b85250114e0674599663da6418cdc4d893947220247be46e16e002f909170b8f86526bd96c4610a515f1ee0c14728e2a77705a55
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
](https://travis-ci.org/Erol/yomu)
|
2
|
+
[](https://codeclimate.com/github/Erol/yomu)
|
2
3
|
|
3
4
|
# Yomu 読む
|
4
5
|
|
data/lib/yomu.rb
CHANGED
@@ -2,7 +2,7 @@ require 'yomu/version'
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'mime/types'
|
5
|
-
require '
|
5
|
+
require 'json'
|
6
6
|
|
7
7
|
class Yomu
|
8
8
|
GEMPATH = File.dirname(File.dirname(__FILE__))
|
@@ -21,11 +21,11 @@ class Yomu
|
|
21
21
|
when :html
|
22
22
|
'-h'
|
23
23
|
when :metadata
|
24
|
-
'-m'
|
24
|
+
'-m -j'
|
25
25
|
when :mimetype
|
26
|
-
'-m'
|
26
|
+
'-m -j'
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
result = IO.popen "#{java} -Djava.awt.headless=true -jar #{Yomu::JARPATH} #{switch}", 'r+' do |io|
|
30
30
|
io.write data
|
31
31
|
io.close_write
|
@@ -38,9 +38,9 @@ class Yomu
|
|
38
38
|
when :html
|
39
39
|
result
|
40
40
|
when :metadata
|
41
|
-
|
41
|
+
JSON.parse(result)
|
42
42
|
when :mimetype
|
43
|
-
MIME::Types[
|
43
|
+
MIME::Types[JSON.parse(result)['Content-Type']].first
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -60,10 +60,10 @@ class Yomu
|
|
60
60
|
|
61
61
|
def initialize(input)
|
62
62
|
if input.is_a? String
|
63
|
-
if input
|
64
|
-
@uri = URI.parse input
|
65
|
-
elsif File.exists? input
|
63
|
+
if File.exists? input
|
66
64
|
@path = input
|
65
|
+
elsif input =~ URI::regexp
|
66
|
+
@uri = URI.parse input
|
67
67
|
else
|
68
68
|
raise Errno::ENOENT.new "missing file or invalid URI - #{input}"
|
69
69
|
end
|
@@ -91,9 +91,9 @@ class Yomu
|
|
91
91
|
# yomu.html
|
92
92
|
|
93
93
|
def html
|
94
|
-
return @
|
94
|
+
return @html if defined? @html
|
95
95
|
|
96
|
-
@
|
96
|
+
@html = Yomu.read :html, data
|
97
97
|
end
|
98
98
|
|
99
99
|
# Returns the metadata hash of the Yomu document.
|
@@ -116,7 +116,9 @@ class Yomu
|
|
116
116
|
def mimetype
|
117
117
|
return @mimetype if defined? @mimetype
|
118
118
|
|
119
|
-
|
119
|
+
type = metadata["Content-Type"].is_a?(Array) ? metadata["Content-Type"].first : metadata["Content-Type"]
|
120
|
+
|
121
|
+
@mimetype = MIME::Types[type].first
|
120
122
|
end
|
121
123
|
|
122
124
|
# Returns +true+ if the Yomu document was specified using a file path.
|
@@ -124,6 +126,18 @@ class Yomu
|
|
124
126
|
# yomu = Yomu.new 'sample.pages'
|
125
127
|
# yomu.path? #=> true
|
126
128
|
|
129
|
+
|
130
|
+
def creation_date
|
131
|
+
return @creation_date if defined? @creation_date
|
132
|
+
|
133
|
+
if metadata['Creation-Date']
|
134
|
+
@creation_date = Time.parse(metadata['Creation-Date'])
|
135
|
+
else
|
136
|
+
nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
127
141
|
def path?
|
128
142
|
defined? @path
|
129
143
|
end
|
@@ -166,11 +180,6 @@ class Yomu
|
|
166
180
|
@data
|
167
181
|
end
|
168
182
|
|
169
|
-
def self.quote(metadata)
|
170
|
-
metadata.gsub(/: (.*: .*)$/, ': "\1"')
|
171
|
-
end
|
172
|
-
private_class_method :quote
|
173
|
-
|
174
183
|
def self.java
|
175
184
|
ENV['JAVA_HOME'] ? ENV['JAVA_HOME'] + '/bin/java' : 'java'
|
176
185
|
end
|
data/lib/yomu/version.rb
CHANGED
data/spec/yomu_spec.rb
CHANGED
@@ -28,12 +28,6 @@ describe Yomu do
|
|
28
28
|
expect( metadata['dc:title'] ).to eql 'problem: test'
|
29
29
|
end
|
30
30
|
|
31
|
-
it 'reads metadata time values as time values' do
|
32
|
-
metadata = Yomu.read :metadata, data
|
33
|
-
|
34
|
-
expect( metadata['Creation-Date'] ).to be_a Time
|
35
|
-
end
|
36
|
-
|
37
31
|
it 'reads mimetype' do
|
38
32
|
mimetype = Yomu.read :mimetype, data
|
39
33
|
|
@@ -100,6 +94,14 @@ describe Yomu do
|
|
100
94
|
end
|
101
95
|
end
|
102
96
|
|
97
|
+
|
98
|
+
describe '.creation_date' do
|
99
|
+
let(:yomu) { Yomu.new 'spec/samples/sample.pages' }
|
100
|
+
it 'should retur Time' do
|
101
|
+
expect( yomu.creation_date ).to be_a Time
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
103
105
|
describe '.java' do
|
104
106
|
specify 'with no specified JAVA_HOME' do
|
105
107
|
expect( Yomu.send(:java) ).to eql 'java'
|
@@ -120,7 +122,7 @@ describe Yomu do
|
|
120
122
|
end
|
121
123
|
|
122
124
|
specify '#metadata reads metadata' do
|
123
|
-
expect( yomu.metadata['Content-Type'] ).to eql
|
125
|
+
expect( yomu.metadata['Content-Type'] ).to eql ["application/vnd.apple.pages", "application/vnd.apple.pages"]
|
124
126
|
end
|
125
127
|
end
|
126
128
|
|
@@ -144,7 +146,7 @@ describe Yomu do
|
|
144
146
|
end
|
145
147
|
|
146
148
|
specify '#metadata reads metadata' do
|
147
|
-
expect( yomu.metadata['Content-Type'] ).to eql
|
149
|
+
expect( yomu.metadata['Content-Type'] ).to eql ["application/vnd.apple.pages", "application/vnd.apple.pages"]
|
148
150
|
end
|
149
151
|
end
|
150
152
|
end
|
data/yomu.gemspec
CHANGED
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'yomu/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'yomu'
|
8
8
|
spec.version = Yomu::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Erol Fornoles']
|
10
|
+
spec.email = ['erol.fornoles@gmail.com']
|
11
11
|
spec.description = %q{Read text and metadata from files and documents (.doc, .docx, .pages, .odt, .rtf, .pdf)}
|
12
12
|
spec.summary = %q{Read text and metadata from files and documents (.doc, .docx, .pages, .odt, .rtf, .pdf)}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'http://erol.github.com/yomu'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'mime-types', '~> 1.23'
|
22
|
+
spec.add_runtime_dependency 'json', '~> 1.8'
|
22
23
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yomu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erol Fornoles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.23'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,6 +90,7 @@ extra_rdoc_files: []
|
|
76
90
|
files:
|
77
91
|
- ".gitignore"
|
78
92
|
- ".rspec"
|
93
|
+
- ".travis.yml"
|
79
94
|
- Gemfile
|
80
95
|
- LICENSE
|
81
96
|
- NOTICE.txt
|
@@ -111,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
126
|
version: '0'
|
112
127
|
requirements: []
|
113
128
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.2.
|
129
|
+
rubygems_version: 2.2.2
|
115
130
|
signing_key:
|
116
131
|
specification_version: 4
|
117
132
|
summary: Read text and metadata from files and documents (.doc, .docx, .pages, .odt,
|