yomu 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yomu.rb CHANGED
@@ -12,7 +12,7 @@ class Yomu
12
12
  # data = File.read 'sample.pages'
13
13
  # text = Yomu.read :text, data
14
14
  # metadata = Yomu.read :metadata, data
15
- #
15
+
16
16
  def self.read(type, data)
17
17
  switch = case type
18
18
  when :text
@@ -21,7 +21,7 @@ class Yomu
21
21
  '-m'
22
22
  end
23
23
 
24
- result = IO.popen "java -Djava.awt.headless=true -jar #{Yomu::JARPATH} #{switch}", 'r+' do |io|
24
+ result = IO.popen "#{java} -Djava.awt.headless=true -jar #{Yomu::JARPATH} #{switch}", 'r+' do |io|
25
25
  io.write data
26
26
  io.close_write
27
27
  io.read
@@ -43,7 +43,7 @@ class Yomu
43
43
  # From a stream or an object which responds to +read+
44
44
  #
45
45
  # Yomu.new File.open('sample.pages')
46
- #
46
+
47
47
  def initialize(input)
48
48
  if input.is_a? String
49
49
  if input =~ URI::regexp
@@ -64,7 +64,7 @@ class Yomu
64
64
  #
65
65
  # yomu = Yomu.new 'sample.pages'
66
66
  # yomu.text
67
- #
67
+
68
68
  def text
69
69
  return @text if defined? @text
70
70
 
@@ -75,7 +75,7 @@ class Yomu
75
75
  #
76
76
  # yomu = Yomu.new 'sample.pages'
77
77
  # yomu.metadata['Content-Type']
78
- #
78
+
79
79
  def metadata
80
80
  return @metadata if defined? @metadata
81
81
 
@@ -86,7 +86,7 @@ class Yomu
86
86
  #
87
87
  # yomu = Yomu.new 'sample.pages'
88
88
  # yomu.path? #=> true
89
- #
89
+
90
90
  def path?
91
91
  defined? @path
92
92
  end
@@ -95,7 +95,7 @@ class Yomu
95
95
  #
96
96
  # yomu = Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx'
97
97
  # yomu.uri? #=> true
98
- #
98
+
99
99
  def uri?
100
100
  defined? @uri
101
101
  end
@@ -105,7 +105,7 @@ class Yomu
105
105
  # file = File.open('sample.pages')
106
106
  # yomu = Yomu.new file
107
107
  # yomu.stream? #=> true
108
- #
108
+
109
109
  def stream?
110
110
  defined? @stream
111
111
  end
@@ -114,7 +114,7 @@ class Yomu
114
114
  #
115
115
  # yomu = Yomu.new 'sample.pages'
116
116
  # yomu.data
117
- #
117
+
118
118
  def data
119
119
  return @data if defined? @data
120
120
 
@@ -128,4 +128,9 @@ class Yomu
128
128
 
129
129
  @data
130
130
  end
131
+
132
+ def self.java
133
+ ENV['JAVA_HOME'] ? ENV['JAVA_HOME'] + '/bin/java' : 'java'
134
+ end
135
+ private_class_method :java
131
136
  end
data/lib/yomu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Yomu
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/test/specs/yomu.rb CHANGED
@@ -3,6 +3,10 @@ require_relative '../helper.rb'
3
3
  describe Yomu do
4
4
  let(:data) { File.read 'test/samples/sample.pages' }
5
5
 
6
+ before do
7
+ ENV['JAVA_HOME'] = nil
8
+ end
9
+
6
10
  describe '.read' do
7
11
  it 'reads text' do
8
12
  text = Yomu.read :text, data
@@ -25,55 +29,65 @@ describe Yomu do
25
29
  end
26
30
 
27
31
  it 'accepts a root path' do
32
+ yomu = nil
33
+
28
34
  assert_silent do
29
35
  yomu = Yomu.new 'test/samples/sample.pages'
30
-
31
- assert_block { yomu.path? }
32
- assert_block { !yomu.uri? }
33
- assert_block { !yomu.stream? }
34
36
  end
37
+
38
+ assert yomu.path?
39
+ refute yomu.uri?
40
+ refute yomu.stream?
35
41
  end
36
42
 
37
43
  it 'accepts a relative path' do
44
+ yomu = nil
45
+
38
46
  assert_silent do
39
47
  yomu = Yomu.new 'test/samples/sample.pages'
40
-
41
- assert_block { yomu.path? }
42
- assert_block { !yomu.uri? }
43
- assert_block { !yomu.stream? }
44
48
  end
49
+
50
+ assert yomu.path?
51
+ refute yomu.uri?
52
+ refute yomu.stream?
45
53
  end
46
54
 
47
55
  it 'accepts a path with spaces' do
56
+ yomu = nil
57
+
48
58
  assert_silent do
49
59
  yomu = Yomu.new 'test/samples/sample filename with spaces.pages'
50
-
51
- assert_block { yomu.path? }
52
- assert_block { !yomu.uri? }
53
- assert_block { !yomu.stream? }
54
60
  end
61
+
62
+ assert yomu.path?
63
+ refute yomu.uri?
64
+ refute yomu.stream?
55
65
  end
56
66
 
57
67
  it 'accepts a URI' do
68
+ yomu = nil
69
+
58
70
  assert_silent do
59
71
  yomu = Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx'
60
-
61
- assert_block { yomu.uri? }
62
- assert_block { !yomu.path? }
63
- assert_block { !yomu.stream? }
64
72
  end
73
+
74
+ assert yomu.uri?
75
+ refute yomu.path?
76
+ refute yomu.stream?
65
77
  end
66
78
 
67
79
  it 'accepts a stream or object that can be read' do
80
+ yomu = nil
81
+
68
82
  assert_silent do
69
83
  File.open 'test/samples/sample.pages', 'r' do |file|
70
84
  yomu = Yomu.new file
71
-
72
- assert_block { yomu.stream? }
73
- assert_block { !yomu.path? }
74
- assert_block { !yomu.uri? }
75
85
  end
76
86
  end
87
+
88
+ assert yomu.stream?
89
+ refute yomu.path?
90
+ refute yomu.uri?
77
91
  end
78
92
 
79
93
  it 'does not accept a path to a missing file' do
@@ -91,51 +105,51 @@ describe Yomu do
91
105
  end
92
106
  end
93
107
 
108
+ describe '.java' do
109
+ specify 'with no specified JAVA_HOME' do
110
+ assert_equal 'java', Yomu.send(:java)
111
+ end
112
+
113
+ specify 'with a specified JAVA_HOME' do
114
+ ENV['JAVA_HOME'] = '/path/to/java/home'
115
+
116
+ assert_equal '/path/to/java/home/bin/java', Yomu.send(:java)
117
+ end
118
+ end
119
+
94
120
  describe 'initialized with a given path' do
95
121
  let(:yomu) { Yomu.new 'test/samples/sample.pages' }
96
122
 
97
- describe '#text' do
98
- it 'reads text' do
99
- assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.'
100
- end
123
+ specify '#text reads text' do
124
+ assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.'
101
125
  end
102
126
 
103
- describe '#metadata' do
104
- it 'reads metadata' do
105
- assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type']
106
- end
127
+ specify '#metada reads metadata' do
128
+ assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type']
107
129
  end
108
130
  end
109
131
 
110
132
  describe 'initialized with a given URI' do
111
133
  let(:yomu) { Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx' }
112
134
 
113
- describe '#text' do
114
- it 'reads text' do
115
- assert_includes yomu.text, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
116
- end
135
+ specify '#text reads text' do
136
+ assert_includes yomu.text, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'
117
137
  end
118
138
 
119
- describe '#metadata' do
120
- it 'reads metadata' do
121
- assert_equal 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', yomu.metadata['Content-Type']
122
- end
139
+ specify '#metadata reads metadata' do
140
+ assert_equal 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', yomu.metadata['Content-Type']
123
141
  end
124
142
  end
125
143
 
126
144
  describe 'initialized with a given stream' do
127
145
  let(:yomu) { Yomu.new File.open('test/samples/sample.pages', 'rb') }
128
146
 
129
- describe '#text' do
130
- it 'reads text' do
131
- assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.'
132
- end
147
+ specify '#text reads text' do
148
+ assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.'
133
149
  end
134
150
 
135
- describe '#metadata' do
136
- it 'reads metadata' do
137
- assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type']
138
- end
151
+ specify '#metadata reads metadata' do
152
+ assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type']
139
153
  end
140
154
  end
141
155
  end
data/yomu.gemspec CHANGED
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "yomu"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Yomu::VERSION
17
+
18
+ gem.add_development_dependency 'minitest'
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yomu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: Read text and metadata from files and documents (.doc, .docx, .pages,
15
31
  .odt, .rtf, .pdf)
16
32
  email: