epub-parser 0.2.5 → 0.2.6

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/test/test_inspect.rb CHANGED
@@ -24,7 +24,7 @@ class TestInspect < Test::Unit::TestCase
24
24
  def test_package_inspects_content_models
25
25
  @package.metadata = Package::Metadata.new
26
26
 
27
- assert_match '@metadata=#<EPUB::Publication::Package::Metadata:', @package.inspect
27
+ assert_match '@metadata=#<EPUB::Metadata:', @package.inspect
28
28
  end
29
29
 
30
30
  class TestMetadata < TestPackage
@@ -45,7 +45,7 @@ class TestInspect < Test::Unit::TestCase
45
45
  title.content = 'Book Title'
46
46
  @metadata.titles << title
47
47
 
48
- title_pattern = '@dc_titles=[#<EPUB::Publication::Package::Metadata::Title'
48
+ title_pattern = '@dc_titles=[#<EPUB::Metadata::Title'
49
49
 
50
50
  assert_match title_pattern, @metadata.inspect
51
51
  end
@@ -54,7 +54,7 @@ class TestInspect < Test::Unit::TestCase
54
54
  meta = Package::Metadata::Title.new
55
55
  meta.content = 'Book Title'
56
56
 
57
- title_pattern = RUBY_VERSION >= '2.0' ? '#<EPUB::Publication::Package::Metadata::Title' : 'Book Title'
57
+ title_pattern = RUBY_VERSION >= '2.0' ? '#<EPUB::Metadata::Title' : 'Book Title'
58
58
 
59
59
  assert_match title_pattern, meta.inspect
60
60
  end
@@ -77,7 +77,7 @@ class TestInspect < Test::Unit::TestCase
77
77
  def test_meta_inspect_includes_class_name
78
78
  meta = Package::Metadata::Meta.new
79
79
 
80
- assert_match /Package::Metadata::Meta/, meta.inspect
80
+ assert_match /Metadata::Meta/, meta.inspect
81
81
  end
82
82
 
83
83
  def test_meta_inspect_includes_instance_variables
@@ -3,14 +3,15 @@ require 'epub/parser'
3
3
 
4
4
  class TestParserFixedLayout < Test::Unit::TestCase
5
5
  def test_using_fixed_layout_is_true_when_rendition_property_in_package_prefix
6
- parser = EPUB::Parser::Publication.new(<<OPF, 'dummy/rootfile.opf')
6
+ opf = <<OPF
7
7
  <package version="3.0"
8
8
  unique-identifier="pub-id"
9
9
  xmlns="http://www.idpf.org/2007/opf"
10
10
  prefix="rendition: http://www.idpf.org/vocab/rendition/#">
11
11
  </package>
12
12
  OPF
13
- package = parser.parse_package
13
+ parser = EPUB::Parser::Publication.new(opf)
14
+ package = parser.parse_package(Nokogiri.XML(opf))
14
15
  assert_true package.using_fixed_layout?
15
16
  end
16
17
  end
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require File.expand_path 'helper', File.dirname(__FILE__)
3
+ require 'zipruby'
3
4
 
4
5
  class TestParserOCF < Test::Unit::TestCase
5
6
  def setup
@@ -10,6 +11,9 @@ class TestParserOCF < Test::Unit::TestCase
10
11
  @container_xml = Zip::Archive.open(file) {|archive|
11
12
  archive.fopen('META-INF/container.xml').read
12
13
  }
14
+ @metadata_xml = Zip::Archive.open(file) {|archive|
15
+ archive.fopen('META-INF/metadata.xml').read
16
+ }
13
17
  end
14
18
 
15
19
  def test_parsed_container_has_one_rootfile
@@ -28,10 +32,21 @@ class TestParserOCF < Test::Unit::TestCase
28
32
  assert_equal 'content', encryption.content
29
33
  end
30
34
 
35
+ def test_parse_metadata_with_unknown_format_do_nothing_excluding_to_have_content
36
+ metadata = @parser.parse_metadata('content')
37
+
38
+ assert_equal 'content', metadata.content
39
+ end
40
+
41
+ def test_parse_metadata_with_multiple_rendition_format_returns_metadata
42
+ metadata = @parser.parse_metadata(@metadata_xml)
43
+
44
+ assert_equal 'urn:uuid:A1B0D67E-2E81-4DF5-9E67-A64CBE366809@2011-01-01T12:00:00Z', metadata.release_identifier
45
+ end
46
+
31
47
  def test_parse
32
48
  assert_nothing_raised do
33
49
  @parser.parse
34
50
  end
35
51
  end
36
52
  end
37
-
@@ -7,8 +7,9 @@ class TestParserPublication < Test::Unit::TestCase
7
7
  rootfile = 'OPS/ルートファイル.opf'
8
8
  @zip = Zip::Archive.open(file)
9
9
  opf = @zip.fopen(rootfile).read
10
- @parser = EPUB::Parser::Publication.new(opf, rootfile)
11
- @package = @parser.parse_package
10
+ @opf = Nokogiri.XML(opf)
11
+ @parser = EPUB::Parser::Publication.new(opf)
12
+ @package = @parser.parse_package(@opf)
12
13
  end
13
14
 
14
15
  def teardown
@@ -20,7 +21,7 @@ class TestParserPublication < Test::Unit::TestCase
20
21
  end
21
22
 
22
23
  def test_has_unique_identifier
23
- @package.metadata = @parser.parse_metadata
24
+ @package.metadata = @parser.parse_metadata(@opf)
24
25
  assert_equal 'pub-id', @package.unique_identifier.id
25
26
  assert_equal 'da265185-8da8-462d-a146-17dd388f61fc', @package.unique_identifier.to_s
26
27
  end
@@ -32,15 +33,16 @@ class TestParserPublication < Test::Unit::TestCase
32
33
  end
33
34
 
34
35
  def test_has_empty_hash_as_prefix_when_no_prefix_attribute
35
- parser = EPUB::Parser::Publication.new('<package></package>', '')
36
- package = parser.parse_package
36
+ opf = '<package></package>'
37
+ parser = EPUB::Parser::Publication.new(opf)
38
+ package = parser.parse_package(Nokogiri.XML(opf))
37
39
  assert_empty package.prefix
38
40
  end
39
41
 
40
42
  class TestParseMetadata < TestParserPublication
41
43
  def setup
42
44
  super
43
- @metadata = @parser.parse_metadata
45
+ @metadata = @parser.parse_metadata(@opf)
44
46
  end
45
47
 
46
48
  def test_has_identifier
@@ -78,7 +80,7 @@ class TestParserPublication < Test::Unit::TestCase
78
80
  class TestParseManifest < TestParserPublication
79
81
  def setup
80
82
  super
81
- @manifest = @parser.parse_manifest
83
+ @package.manifest = @manifest = @parser.parse_manifest(@opf)
82
84
  end
83
85
 
84
86
  def test_manifest_has_19_items
@@ -164,7 +166,7 @@ class TestParserPublication < Test::Unit::TestCase
164
166
  class TestParseSpine < TestParserPublication
165
167
  def setup
166
168
  super
167
- @spine = @parser.parse_spine
169
+ @spine = @parser.parse_spine(@opf)
168
170
  end
169
171
 
170
172
  def atest_each_itemref_yields_itemref_in_order_on_spine_element
@@ -184,7 +186,7 @@ class TestParserPublication < Test::Unit::TestCase
184
186
  class TestParseGuide < TestParserPublication
185
187
  def setup
186
188
  super
187
- @guide = @parser.parse_guide
189
+ @package.guide = @guide = @parser.parse_guide(@opf)
188
190
  end
189
191
 
190
192
  def test_guide_has_one_reference
@@ -197,7 +199,7 @@ class TestParserPublication < Test::Unit::TestCase
197
199
  end
198
200
 
199
201
  def test_reference_refers_item
200
- @parser.parse_manifest
202
+ @package.manifest = @parser.parse_manifest(@opf)
201
203
 
202
204
  assert_instance_of EPUB::Publication::Package::Manifest::Item, @guide.cover.item
203
205
  end
@@ -206,9 +208,8 @@ class TestParserPublication < Test::Unit::TestCase
206
208
  class TestParseBindings < TestParserPublication
207
209
  def setup
208
210
  super
209
- @package.manifest = @parser.parse_manifest
210
- @bindings = @parser.parse_bindings
211
- @bindings.package = @package
211
+ @package.manifest = @parser.parse_manifest(@opf)
212
+ @package.bindings = @bindings = @parser.parse_bindings(@opf, @package.manifest)
212
213
  end
213
214
 
214
215
  def test_has_one_bindings
@@ -19,6 +19,10 @@ class TestPublication < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  class TestMetadata < TestPublication
22
+ def setup
23
+ @metadata = Package::Metadata.new
24
+ end
25
+
22
26
  def test_meta_refines_setter_connect_refinee_to_the_meta
23
27
  refiner = Package::Metadata::Meta.new
24
28
  refinee = Package::Metadata::Meta.new
@@ -135,6 +139,38 @@ class TestPublication < Test::Unit::TestCase
135
139
  assert_true meta.subexpression?
136
140
  end
137
141
 
142
+ def test_modified_returns_meta_with_modified_property
143
+ modified = Package::Metadata::Meta.new
144
+ modified.property = 'dcterms:modified'
145
+
146
+ @metadata.metas << modified
147
+
148
+ assert_equal modified, @metadata.modified
149
+ end
150
+
151
+ def test_modified_doesnt_return_meta_with_modified_property_refined
152
+ modified = Package::Metadata::Meta.new
153
+ modified.property = 'dcterms:modified'
154
+ refiner = Package::Metadata::Meta.new
155
+ refiner.refines = modified
156
+ @metadata.metas << modified << refiner
157
+
158
+ assert_nil @metadata.modified
159
+ end
160
+
161
+ def test_modified_returns_meta_with_modified_property_not_refined
162
+ modified1 = Package::Metadata::Meta.new
163
+ modified1.property = 'dcterms:modified'
164
+ refiner = Package::Metadata::Meta.new
165
+ refiner.refines = modified1
166
+ modified2 = Package::Metadata::Meta.new
167
+ modified2.property = 'dcterms:modified'
168
+
169
+ @metadata.metas << modified1 << refiner << modified2
170
+
171
+ assert_equal modified2, @metadata.modified
172
+ end
173
+
138
174
  class TestIdentifier < self
139
175
  def setup
140
176
  @identifier = Package::Metadata::Identifier.new
@@ -8,7 +8,7 @@ class TestSearcher < Test::Unit::TestCase
8
8
  super
9
9
  opf_path = File.expand_path('../fixtures/book/OPS/ルートファイル.opf', __FILE__)
10
10
  nav_path = File.expand_path('../fixtures/book/OPS/nav.xhtml', __FILE__)
11
- @package = EPUB::Parser::Publication.new(open(opf_path), 'OPS/ルートファイル.opf').parse
11
+ @package = EPUB::Parser::Publication.new(open(opf_path)).parse
12
12
  @package.spine.each_itemref do |itemref|
13
13
  stub(itemref.item).read {
14
14
  itemref.idref == 'nav' ? File.read(nav_path) : '<html></html>'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubygems-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: zipruby
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +220,20 @@ dependencies:
206
220
  - - ">="
207
221
  - !ruby/object:Gem::Version
208
222
  version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pretty_backtrace
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: archive-zip
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -295,6 +323,8 @@ files:
295
323
  - docs/UnpackedArchive.markdown
296
324
  - epub-parser.gemspec
297
325
  - examples/aggregate-contents-from-web.rb
326
+ - examples/exctract-content-using-cfi.rb
327
+ - examples/find-elements-and-cfis.rb
298
328
  - lib/epub.rb
299
329
  - lib/epub/book.rb
300
330
  - lib/epub/book/features.rb
@@ -304,6 +334,7 @@ files:
304
334
  - lib/epub/content_document/navigation.rb
305
335
  - lib/epub/content_document/xhtml.rb
306
336
  - lib/epub/inspector.rb
337
+ - lib/epub/metadata.rb
307
338
  - lib/epub/ocf.rb
308
339
  - lib/epub/ocf/container.rb
309
340
  - lib/epub/ocf/encryption.rb
@@ -321,6 +352,7 @@ files:
321
352
  - lib/epub/parser/cfi.tab.rb
322
353
  - lib/epub/parser/cfi.y
323
354
  - lib/epub/parser/content_document.rb
355
+ - lib/epub/parser/metadata.rb
324
356
  - lib/epub/parser/ocf.rb
325
357
  - lib/epub/parser/publication.rb
326
358
  - lib/epub/parser/utils.rb
@@ -339,6 +371,7 @@ files:
339
371
  - lib/epub/searcher/xhtml.rb
340
372
  - man/epubinfo.1.ronn
341
373
  - test/fixtures/book/META-INF/container.xml
374
+ - test/fixtures/book/META-INF/metadata.xml
342
375
  - test/fixtures/book/OPS/%E6%97%A5%E6%9C%AC%E8%AA%9E.xhtml
343
376
  - test/fixtures/book/OPS/case-sensitive.xhtml
344
377
  - test/fixtures/book/OPS/containing space.xhtml
@@ -405,4 +438,3 @@ test_files:
405
438
  - test/test_parser_publication.rb
406
439
  - test/test_publication.rb
407
440
  - test/test_searcher.rb
408
- has_rdoc: yard