epub-parser 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -3
- data/.yardopts +1 -0
- data/CHANGELOG.markdown +12 -0
- data/README.markdown +15 -11
- data/Rakefile +11 -6
- data/bin/epub-open +1 -1
- data/bin/epubinfo +1 -1
- data/docs/AggregateContentsFromWeb.markdown +1 -1
- data/docs/UnpackedArchive.markdown +2 -2
- data/epub-parser.gemspec +3 -2
- data/lib/epub/book/features.rb +5 -1
- data/lib/epub/cfi.rb +301 -0
- data/lib/epub/content_document/navigation.rb +6 -1
- data/lib/epub/content_document/xhtml.rb +1 -2
- data/lib/epub/ocf/physical_container.rb +2 -1
- data/lib/epub/ocf/physical_container/{file.rb → unpacked_directory.rb} +1 -1
- data/lib/epub/parser/cfi.rb +84 -0
- data/lib/epub/parser/cfi.y +187 -0
- data/lib/epub/parser/content_document.rb +1 -1
- data/lib/epub/parser/publication.rb +3 -4
- data/lib/epub/parser/version.rb +1 -1
- data/lib/epub/publication/package/guide.rb +6 -1
- data/lib/epub/publication/package/manifest.rb +24 -8
- data/lib/epub/publication/package/metadata.rb +9 -5
- data/lib/epub/searcher/publication.rb +0 -2
- data/test/helper.rb +2 -0
- data/test/test_cfi.rb +227 -0
- data/test/test_content_document.rb +1 -1
- data/test/test_ocf_physical_container.rb +2 -2
- data/test/test_parser.rb +3 -3
- data/test/test_parser_cfi.rb +38 -0
- data/test/test_parser_content_document.rb +1 -1
- data/test/test_publication.rb +12 -4
- metadata +25 -23
- data/features/epubinfo.feature +0 -6
- data/features/step_definitions/epubinfo_steps.rb +0 -5
- data/features/support/env.rb +0 -1
@@ -52,6 +52,10 @@ module EPUB
|
|
52
52
|
languages.first
|
53
53
|
end
|
54
54
|
|
55
|
+
def modified
|
56
|
+
metas.find {|meta| meta.property == 'dcterms:modified'}
|
57
|
+
end
|
58
|
+
|
55
59
|
def to_h
|
56
60
|
DC_ELEMS.inject({}) do |hsh, elem|
|
57
61
|
hsh[elem] = __send__(elem)
|
@@ -94,20 +98,20 @@ module EPUB
|
|
94
98
|
class Identifier < DCMES
|
95
99
|
# @note This is ad-hoc
|
96
100
|
# @todo Define and include OPF module for opf:scheme attribute
|
97
|
-
# @todo Define
|
101
|
+
# @todo Define general way to handle with identifier-type refiners
|
98
102
|
attr_accessor :scheme
|
99
103
|
|
100
104
|
# @note This is ad-hoc
|
101
105
|
# @todo Define and include OPF module for opf:scheme attribute
|
102
|
-
# @todo Define
|
106
|
+
# @todo Define general way to handle with identifier-type refiners
|
103
107
|
def isbn?
|
108
|
+
scheme == 'ISBN' or
|
109
|
+
content.to_s.downcase.start_with? 'urn:isbn' or
|
104
110
|
refiners.any? {|refiner|
|
105
111
|
refiner.property == 'identifier-type' and
|
106
112
|
refiner.scheme == 'onix:codelist5' and
|
107
113
|
%w[02 15].include? refiner.content
|
108
|
-
}
|
109
|
-
scheme == 'ISBN' or
|
110
|
-
content.to_s.downcase.start_with? 'urn:isbn'
|
114
|
+
}
|
111
115
|
end
|
112
116
|
end
|
113
117
|
|
@@ -4,7 +4,6 @@ module EPUB
|
|
4
4
|
module Searcher
|
5
5
|
class Publication
|
6
6
|
class << self
|
7
|
-
# @todo Use named argument in the future
|
8
7
|
def search(package, word, **options)
|
9
8
|
new(word).search(package, options)
|
10
9
|
end
|
@@ -14,7 +13,6 @@ module EPUB
|
|
14
13
|
@word = word
|
15
14
|
end
|
16
15
|
|
17
|
-
# @todo Use named argument in the future
|
18
16
|
def search(package, algorithm: :seamless)
|
19
17
|
results = []
|
20
18
|
|
data/test/helper.rb
CHANGED
data/test/test_cfi.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'helper'
|
3
|
+
require 'epub/cfi'
|
4
|
+
require 'epub/parser/cfi'
|
5
|
+
require 'nokogiri/diff'
|
6
|
+
|
7
|
+
class TestCFI < Test::Unit::TestCase
|
8
|
+
def test_escape
|
9
|
+
assert_equal '^^^[^]^(^)^,^;^=', EPUB::CFI.escape('^[](),;=')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_unescape
|
13
|
+
assert_equal '^[](),;=', EPUB::CFI.unescape('^^^[^]^(^)^,^;^=')
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestPath < self
|
17
|
+
data([
|
18
|
+
'/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]',
|
19
|
+
'/6/4!/4/10/2/1:3[Ф-"spa ce"-99%-aa^[bb^]^^]',
|
20
|
+
'/6/4!/4/10/2/1:3[Ф-"spa%20ce"-99%25-aa^[bb^]^^]',
|
21
|
+
'/6/4!/4/10/2/1:3[%d0%a4-"spa%20ce"-99%25-aa^[bb^]^^]',
|
22
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]',
|
23
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]',
|
24
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[,y]',
|
25
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[;s=b]',
|
26
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy;s=b]',
|
27
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2[;s=b]',
|
28
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/3:10',
|
29
|
+
'/6/4[chap01ref]!/4[body01]/16[svgimg]',
|
30
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/1:0',
|
31
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2/1:0',
|
32
|
+
'/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3',
|
33
|
+
].reduce({}) {|data, cfi|
|
34
|
+
data[cfi] = cfi
|
35
|
+
data
|
36
|
+
})
|
37
|
+
def test_to_s(cfi)
|
38
|
+
assert_equal cfi, epubcfi(cfi).to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
data([
|
42
|
+
'epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])',
|
43
|
+
'epubcfi(/6/4!/4/10/2/1:3[Ф-"spa ce"-99%-aa^[bb^]^^])',
|
44
|
+
'epubcfi(/6/4!/4/10/2/1:3[Ф-"spa%20ce"-99%25-aa^[bb^]^^])',
|
45
|
+
'epubcfi(/6/4!/4/10/2/1:3[%d0%a4-"spa%20ce"-99%25-aa^[bb^]^^])',
|
46
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy])',
|
47
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y])',
|
48
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[,y])',
|
49
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[;s=b])',
|
50
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy;s=b])',
|
51
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2[;s=b])',
|
52
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:10)',
|
53
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/16[svgimg])',
|
54
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:0)',
|
55
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:0)',
|
56
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3)',
|
57
|
+
].reduce({}) {|data, cfi|
|
58
|
+
data[cfi] = cfi
|
59
|
+
data
|
60
|
+
})
|
61
|
+
def test_to_fragment(cfi)
|
62
|
+
assert_equal cfi, EPUB::Parser::CFI.parse(cfi).to_fragment
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_compare
|
66
|
+
assert_equal -1, epubcfi('/6/4[id]') <=> epubcfi('/6/5')
|
67
|
+
assert_equal 0, epubcfi('/6/4') <=> epubcfi('/6/4')
|
68
|
+
assert_equal 1, epubcfi('/6/4') <=> epubcfi('/4/6')
|
69
|
+
assert_equal 1, epubcfi('/6/4!/4@3:7') <=> epubcfi('/6/4!/4')
|
70
|
+
assert_equal 1,
|
71
|
+
epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]') <=>
|
72
|
+
epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]')
|
73
|
+
assert_nil epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/3:10') <=>
|
74
|
+
epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/3!:10')
|
75
|
+
assert_equal 1, epubcfi('/6/4') <=> epubcfi('/6')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class TestRange < self
|
80
|
+
def test_attributes
|
81
|
+
parent = epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]')
|
82
|
+
first = epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/2/1:1')
|
83
|
+
last = epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/3:4')
|
84
|
+
range = epubcfi('/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4')
|
85
|
+
assert_equal 0, first <=> range.first
|
86
|
+
assert_equal 0, last <=> range.last
|
87
|
+
|
88
|
+
assert_equal 0, parent <=> range.parent
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_to_s
|
92
|
+
assert_equal 'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:1)..epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:4)', epubcfi('/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4').to_s
|
93
|
+
assert_equal 'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]!/2/1:1)..epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]!/3:4)', epubcfi('/6/4[chap01ref]!/4[body01]/10[para05],!/2/1:1,!/3:4').to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_to_fragment
|
97
|
+
cfi = '/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4'
|
98
|
+
assert_equal 'epubcfi(' + cfi + ')', epubcfi('/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4').to_fragment
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_cover
|
102
|
+
assert_true epubcfi('/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4').cover? epubcfi('/6/4[chap01ref]!/4[body01]/10[para05]/2/2/4')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class TestStep < self
|
107
|
+
def test_to_s
|
108
|
+
assert_equal '/6', EPUB::CFI::Step.new(6).to_s
|
109
|
+
assert_equal '/4[id]', EPUB::CFI::Step.new(4, EPUB::CFI::IDAssertion.new('id')).to_s
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_compare
|
113
|
+
assert_equal 0, EPUB::CFI::Step.new(6) <=> EPUB::CFI::Step.new(6, 'assertion')
|
114
|
+
assert_equal -1, EPUB::CFI::Step.new(6) <=> EPUB::CFI::Step.new(7)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class TestIDAssertion < self
|
119
|
+
def test_to_s
|
120
|
+
assert_equal '[id]', EPUB::CFI::IDAssertion.new('id').to_s
|
121
|
+
assert_equal '[id;p=a]', EPUB::CFI::IDAssertion.new('id', {'p' => ['a']}).to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class TestTextLocationAssertion < self
|
126
|
+
def test_to_s
|
127
|
+
assert_equal '[yyy]', EPUB::CFI::TextLocationAssertion.new('yyy').to_s
|
128
|
+
assert_equal '[xx,y]', EPUB::CFI::TextLocationAssertion.new('xx', 'y').to_s
|
129
|
+
assert_equal '[,y]', EPUB::CFI::TextLocationAssertion.new(nil, 'y').to_s
|
130
|
+
assert_equal '[;s=b]', EPUB::CFI::TextLocationAssertion.new(nil, nil, {'s' => ['b']}).to_s
|
131
|
+
assert_equal '[yyy;s=b]', EPUB::CFI::TextLocationAssertion.new('yyy', nil, {'s' => ['b']}).to_s
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class TestCharacterOffset < self
|
136
|
+
def test_to_s
|
137
|
+
assert_equal ':1', EPUB::CFI::CharacterOffset.new(1).to_s
|
138
|
+
assert_equal ':2[yyy]', EPUB::CFI::CharacterOffset.new(2, EPUB::CFI::TextLocationAssertion.new('yyy')).to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_compare
|
142
|
+
assert_equal 0,
|
143
|
+
EPUB::CFI::CharacterOffset.new(3) <=>
|
144
|
+
EPUB::CFI::CharacterOffset.new(3, EPUB::CFI::TextLocationAssertion.new('yyy'))
|
145
|
+
assert_equal -1,
|
146
|
+
EPUB::CFI::CharacterOffset.new(4) <=>
|
147
|
+
EPUB::CFI::CharacterOffset.new(5)
|
148
|
+
assert_equal 1,
|
149
|
+
EPUB::CFI::CharacterOffset.new(4, EPUB::CFI::TextLocationAssertion.new(nil, 'xx')) <=>
|
150
|
+
EPUB::CFI::CharacterOffset.new(2)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class TestSpatialOffset < self
|
155
|
+
def test_to_s
|
156
|
+
assert_equal '@0.5:30.2', EPUB::CFI::TemporalSpatialOffset.new(nil, 0.5, 30.2).to_s
|
157
|
+
assert_equal '@0:100', EPUB::CFI::TemporalSpatialOffset.new(nil, 0, 100).to_s
|
158
|
+
assert_equal '@50:50.0', EPUB::CFI::TemporalSpatialOffset.new(nil, 50, 50.0).to_s
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_compare
|
162
|
+
assert_equal 0,
|
163
|
+
EPUB::CFI::TemporalSpatialOffset.new(nil, 30, 40) <=>
|
164
|
+
EPUB::CFI::TemporalSpatialOffset.new(nil, 30, 40)
|
165
|
+
assert_equal 1,
|
166
|
+
EPUB::CFI::TemporalSpatialOffset.new(nil, 30, 40) <=>
|
167
|
+
EPUB::CFI::TemporalSpatialOffset.new(nil, 40, 30)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
class TestTemporalOffset < self
|
172
|
+
def test_to_s
|
173
|
+
assert_equal '~23.5', EPUB::CFI::TemporalSpatialOffset.new(23.5).to_s
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_compare
|
177
|
+
assert_equal 0,
|
178
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5) <=>
|
179
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5)
|
180
|
+
assert_equal -1,
|
181
|
+
EPUB::CFI::TemporalSpatialOffset.new(23) <=>
|
182
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
class TestTemporalSpatialOffset < self
|
187
|
+
def test_to_s
|
188
|
+
assert_equal '~23.5@50:30.0', EPUB::CFI::TemporalSpatialOffset.new(23.5, 50, 30.0).to_s
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_compare
|
192
|
+
assert_equal 0,
|
193
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 30, 40) <=>
|
194
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 30, 40.0)
|
195
|
+
assert_equal 1,
|
196
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 30, 40) <=>
|
197
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5)
|
198
|
+
assert_equal -1,
|
199
|
+
EPUB::CFI::TemporalSpatialOffset.new(nil, 30, 40) <=>
|
200
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 30, 40)
|
201
|
+
assert_equal -1,
|
202
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 30, 40) <=>
|
203
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 30, 50)
|
204
|
+
assert_equal 1,
|
205
|
+
EPUB::CFI::TemporalSpatialOffset.new(24, 30, 40) <=>
|
206
|
+
EPUB::CFI::TemporalSpatialOffset.new(23.5, 100, 100)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
def epubcfi(string)
|
213
|
+
EPUB::Parser::CFI.new.parse(string)
|
214
|
+
end
|
215
|
+
|
216
|
+
def assert_equal_node(expected, actual, message='')
|
217
|
+
diff = AssertionMessage.delayed_diff(expected.to_s, actual.to_s)
|
218
|
+
message = build_message(message, <<EOT, expected, actual, diff)
|
219
|
+
<?>
|
220
|
+
expected but was
|
221
|
+
<?>.?
|
222
|
+
EOT
|
223
|
+
assert_block message do
|
224
|
+
expected.tdiff_equal actual
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
@@ -65,7 +65,7 @@ class TestContentDocument < Test::Unit::TestCase
|
|
65
65
|
item = EPUB::Publication::Package::Manifest::Item.new
|
66
66
|
item.media_type = 'application/xhtml+xml'
|
67
67
|
item.properties = %w[nav]
|
68
|
-
item.href =
|
68
|
+
item.href = 'nav.xhtml'
|
69
69
|
stub(item).read {File.read(File.expand_path('../fixtures/book/OPS/nav.xhtml', __FILE__))}
|
70
70
|
manifest << item
|
71
71
|
nav_doc = EPUB::Parser::ContentDocument.new(item).parse
|
@@ -53,13 +53,13 @@ class TestOCFPhysicalContainer < Test::Unit::TestCase
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
class
|
56
|
+
class TestUnpackedDirectory < self
|
57
57
|
include ConcreteContainer
|
58
58
|
|
59
59
|
def setup
|
60
60
|
super
|
61
61
|
@container_path = @container_path[0..-'.epub'.length-1]
|
62
|
-
@class = EPUB::OCF::PhysicalContainer::
|
62
|
+
@class = EPUB::OCF::PhysicalContainer::UnpackedDirectory
|
63
63
|
@container = @class.new(@container_path)
|
64
64
|
end
|
65
65
|
|
data/test/test_parser.rb
CHANGED
@@ -29,7 +29,7 @@ class TestParser < Test::Unit::TestCase
|
|
29
29
|
def test_parse_from_file_system
|
30
30
|
adapter = EPUB::OCF::PhysicalContainer.adapter
|
31
31
|
begin
|
32
|
-
EPUB::OCF::PhysicalContainer.adapter = :
|
32
|
+
EPUB::OCF::PhysicalContainer.adapter = :UnpackedDirectory
|
33
33
|
epub = EPUB::Parser.parse('test/fixtures/book')
|
34
34
|
assert_instance_of EPUB::Book, epub
|
35
35
|
assert_equal 'Mon premier guide de cuisson, un Mémoire', epub.main_title
|
@@ -39,11 +39,11 @@ class TestParser < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_can_specify_container_adapter_when_parsing_individually
|
42
|
-
epub = EPUB::Parser.parse('test/fixtures/book', container_adapter: :
|
42
|
+
epub = EPUB::Parser.parse('test/fixtures/book', container_adapter: :UnpackedDirectory)
|
43
43
|
|
44
44
|
assert_equal 'Mon premier guide de cuisson, un Mémoire', epub.main_title
|
45
45
|
assert_equal File.read('test/fixtures/book/OPS/nav.xhtml'), epub.nav.read
|
46
|
-
assert_equal EPUB::OCF::PhysicalContainer::
|
46
|
+
assert_equal EPUB::OCF::PhysicalContainer::UnpackedDirectory, epub.container_adapter
|
47
47
|
assert_equal EPUB::OCF::PhysicalContainer::Zipruby, EPUB::OCF::PhysicalContainer.adapter
|
48
48
|
end
|
49
49
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'helper'
|
3
|
+
require 'epub/parser/cfi'
|
4
|
+
|
5
|
+
class TestParserCFI < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@parser = EPUB::Parser::CFI.new(debug: true)
|
8
|
+
end
|
9
|
+
|
10
|
+
# from http://www.idpf.org/epub/linking/cfi/epub-cfi.html
|
11
|
+
data([
|
12
|
+
'epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])',
|
13
|
+
'epubcfi(/6/4!/4/10/2/1:3[Ф-"spa ce"-99%-aa^[bb^]^^])',
|
14
|
+
'epubcfi(/6/4!/4/10/2/1:3[Ф-"spa%20ce"-99%25-aa^[bb^]^^])',
|
15
|
+
'epubcfi(/6/4!/4/10/2/1:3[%d0%a4-"spa%20ce"-99%25-aa^[bb^]^^])',
|
16
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy])',
|
17
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y])',
|
18
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[,y])',
|
19
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[;s=b])',
|
20
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy;s=b])',
|
21
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2[;s=b])',
|
22
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/3:10)',
|
23
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/16[svgimg])',
|
24
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:0)',
|
25
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:0)',
|
26
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3)',
|
27
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4)',
|
28
|
+
'epubcfi(/6,:1,:3)'
|
29
|
+
].reduce({}) {|data, cfi|
|
30
|
+
data[cfi] = cfi
|
31
|
+
data
|
32
|
+
})
|
33
|
+
def test_raise_no_error_on_parsing_valid_cfi(cfi)
|
34
|
+
assert_nothing_raised do
|
35
|
+
@parser.parse(cfi)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -7,7 +7,7 @@ class TestParserContentDocument < Test::Unit::TestCase
|
|
7
7
|
%w[item-1.xhtml item-2.xhtml nav.xhtml].each.with_index do |href, index|
|
8
8
|
item = EPUB::Publication::Package::Manifest::Item.new
|
9
9
|
item.id = index
|
10
|
-
item.href =
|
10
|
+
item.href = href
|
11
11
|
@manifest << item
|
12
12
|
end
|
13
13
|
|
data/test/test_publication.rb
CHANGED
@@ -280,19 +280,27 @@ class TestPublication < Test::Unit::TestCase
|
|
280
280
|
|
281
281
|
def test_find_item_by_relative_iri_returns_item_which_has_resolved_iri_as_href
|
282
282
|
manifest = Package::Manifest.new
|
283
|
-
manifest << xhtml_item = Package::Manifest::Item.new.tap {|item| item.href =
|
284
|
-
manifest << image_item = Package::Manifest::Item.new.tap {|item| item.href =
|
283
|
+
manifest << xhtml_item = Package::Manifest::Item.new.tap {|item| item.href = 'text/01.xhtml'}
|
284
|
+
manifest << image_item = Package::Manifest::Item.new.tap {|item| item.href = 'image/01.png'}
|
285
285
|
|
286
286
|
assert_equal image_item, xhtml_item.find_item_by_relative_iri(Addressable::URI.parse('../image/01.png'))
|
287
287
|
end
|
288
288
|
|
289
289
|
def test_find_item_by_relative_iri_returns_nil_when_no_item_found
|
290
290
|
manifest = Package::Manifest.new
|
291
|
-
manifest << xhtml_item = Package::Manifest::Item.new.tap {|item| item.href =
|
291
|
+
manifest << xhtml_item = Package::Manifest::Item.new.tap {|item| item.href = 'text/01.xhtml'}
|
292
292
|
|
293
293
|
assert_nil xhtml_item.find_item_by_relative_iri(Addressable::URI.parse('../image/01.png'))
|
294
294
|
end
|
295
295
|
|
296
|
+
def test_find_item_by_relative_iri_raises_error_when_iri_starts_with_slash
|
297
|
+
item = Package::Manifest::Item.new
|
298
|
+
|
299
|
+
assert_raise ArgumentError do
|
300
|
+
item.find_item_by_relative_iri Addressable::URI.parse('/starting/with/slash')
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
296
304
|
data('UTF-8' => [Encoding::UTF_8, 'utf-8-encoded'],
|
297
305
|
'EUC-JP' => [Encoding::EUC_JP, 'euc-jp-encoded'],
|
298
306
|
'Shift-JIS' => [Encoding::Shift_JIS, 'shift_jis-encoded'])
|
@@ -305,7 +313,7 @@ class TestPublication < Test::Unit::TestCase
|
|
305
313
|
|
306
314
|
def test_entry_name_returns_normalized_iri
|
307
315
|
item = Package::Manifest::Item.new
|
308
|
-
item.href =
|
316
|
+
item.href = '../style.css'
|
309
317
|
obj = Object.new
|
310
318
|
stub(item).manifest {obj}
|
311
319
|
stub(obj).package {obj}
|
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.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -179,7 +179,7 @@ dependencies:
|
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
182
|
+
name: racc
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
@@ -193,13 +193,13 @@ dependencies:
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: nokogiri-diff
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: '0'
|
202
|
-
type: :
|
202
|
+
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
@@ -207,33 +207,33 @@ dependencies:
|
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
210
|
+
name: zipruby
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
|
-
- - "
|
213
|
+
- - ">="
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: '
|
215
|
+
version: '0'
|
216
216
|
type: :runtime
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
|
-
- - "
|
220
|
+
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: '
|
222
|
+
version: '0'
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
224
|
+
name: nokogiri
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
|
-
- - "
|
227
|
+
- - "~>"
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: '
|
229
|
+
version: '1.6'
|
230
230
|
type: :runtime
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
|
-
- - "
|
234
|
+
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: '
|
236
|
+
version: '1.6'
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
238
|
name: addressable
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -295,12 +295,10 @@ files:
|
|
295
295
|
- docs/UnpackedArchive.markdown
|
296
296
|
- epub-parser.gemspec
|
297
297
|
- examples/aggregate-contents-from-web.rb
|
298
|
-
- features/epubinfo.feature
|
299
|
-
- features/step_definitions/epubinfo_steps.rb
|
300
|
-
- features/support/env.rb
|
301
298
|
- lib/epub.rb
|
302
299
|
- lib/epub/book.rb
|
303
300
|
- lib/epub/book/features.rb
|
301
|
+
- lib/epub/cfi.rb
|
304
302
|
- lib/epub/constants.rb
|
305
303
|
- lib/epub/content_document.rb
|
306
304
|
- lib/epub/content_document/navigation.rb
|
@@ -313,12 +311,15 @@ files:
|
|
313
311
|
- lib/epub/ocf/metadata.rb
|
314
312
|
- lib/epub/ocf/physical_container.rb
|
315
313
|
- lib/epub/ocf/physical_container/archive_zip.rb
|
316
|
-
- lib/epub/ocf/physical_container/
|
314
|
+
- lib/epub/ocf/physical_container/unpacked_directory.rb
|
317
315
|
- lib/epub/ocf/physical_container/unpacked_uri.rb
|
318
316
|
- lib/epub/ocf/physical_container/zipruby.rb
|
319
317
|
- lib/epub/ocf/rights.rb
|
320
318
|
- lib/epub/ocf/signatures.rb
|
321
319
|
- lib/epub/parser.rb
|
320
|
+
- lib/epub/parser/cfi.rb
|
321
|
+
- lib/epub/parser/cfi.tab.rb
|
322
|
+
- lib/epub/parser/cfi.y
|
322
323
|
- lib/epub/parser/content_document.rb
|
323
324
|
- lib/epub/parser/ocf.rb
|
324
325
|
- lib/epub/parser/publication.rb
|
@@ -354,12 +355,14 @@ files:
|
|
354
355
|
- test/fixtures/book/OPS/日本語.xhtml
|
355
356
|
- test/fixtures/book/mimetype
|
356
357
|
- test/helper.rb
|
358
|
+
- test/test_cfi.rb
|
357
359
|
- test/test_content_document.rb
|
358
360
|
- test/test_epub.rb
|
359
361
|
- test/test_fixed_layout.rb
|
360
362
|
- test/test_inspect.rb
|
361
363
|
- test/test_ocf_physical_container.rb
|
362
364
|
- test/test_parser.rb
|
365
|
+
- test/test_parser_cfi.rb
|
363
366
|
- test/test_parser_content_document.rb
|
364
367
|
- test/test_parser_fixed_layout.rb
|
365
368
|
- test/test_parser_ocf.rb
|
@@ -386,21 +389,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
386
389
|
version: '0'
|
387
390
|
requirements: []
|
388
391
|
rubyforge_project:
|
389
|
-
rubygems_version: 2.
|
392
|
+
rubygems_version: 2.5.1
|
390
393
|
signing_key:
|
391
394
|
specification_version: 4
|
392
395
|
summary: EPUB 3 Parser
|
393
396
|
test_files:
|
394
|
-
- features/epubinfo.feature
|
395
|
-
- features/step_definitions/epubinfo_steps.rb
|
396
|
-
- features/support/env.rb
|
397
397
|
- test/helper.rb
|
398
|
+
- test/test_cfi.rb
|
398
399
|
- test/test_content_document.rb
|
399
400
|
- test/test_epub.rb
|
400
401
|
- test/test_fixed_layout.rb
|
401
402
|
- test/test_inspect.rb
|
402
403
|
- test/test_ocf_physical_container.rb
|
403
404
|
- test/test_parser.rb
|
405
|
+
- test/test_parser_cfi.rb
|
404
406
|
- test/test_parser_content_document.rb
|
405
407
|
- test/test_parser_fixed_layout.rb
|
406
408
|
- test/test_parser_ocf.rb
|