epub-cfi 0.1.0 → 0.1.1
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/ChangeLog.md +5 -0
- data/README.md +2 -2
- data/epub-cfi.gemspec +1 -2
- data/lib/epub/cfi.rb +25 -28
- data/lib/epub/cfi/version.rb +1 -1
- data/test/test_cfi.rb +3 -0
- data/test/test_parser.rb +4 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdbce4ceaf9a43a511b16ea3919f1f0f028eedbf
|
4
|
+
data.tar.gz: fbb26bf902a5b301fa041bbe1d251bc33c840d7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 450c3498f4bc08da4fc5159239fb95e13ecdce20c22175a1d7be35a8390aef947097005a5a8b5bc09e3944d2c53a9f280b764e669f6b3cb3a4a8df8af690e923
|
7
|
+
data.tar.gz: 781bb732392cfcc3c287465d6e2489ecaa6d6ec1a779f4443bf22416e93839a0a9b54bbc8adbf67347d24f00d7c842d073f2da8d520af68900441459bbd32f58
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -34,8 +34,8 @@ Examples
|
|
34
34
|
location1 = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]")
|
35
35
|
location2 = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]")
|
36
36
|
location1 < location2 # => true
|
37
|
-
location1 <=>
|
38
|
-
#
|
37
|
+
location1 <=> location2 # => -1
|
38
|
+
# location1 appears earlier than location2
|
39
39
|
|
40
40
|
range = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4")
|
41
41
|
# => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:1>..#<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/3:4>
|
data/epub-cfi.gemspec
CHANGED
@@ -29,8 +29,7 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
30
30
|
gem.require_paths = ['lib']
|
31
31
|
|
32
|
-
gem.
|
33
|
-
|
32
|
+
gem.add_development_dependency "racc"
|
34
33
|
gem.add_development_dependency 'rake'
|
35
34
|
gem.add_development_dependency 'rubygems-tasks'
|
36
35
|
gem.add_development_dependency 'yard'
|
data/lib/epub/cfi.rb
CHANGED
@@ -20,6 +20,27 @@ module EPUB
|
|
20
20
|
|
21
21
|
attr_reader :paths
|
22
22
|
|
23
|
+
class << self
|
24
|
+
def from_parent_and_subpath(parent_path, subpath)
|
25
|
+
new(resolve_path(parent_path, subpath))
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def resolve_path(parent_path, subpath)
|
31
|
+
paths = parent_path.collect(&:dup)
|
32
|
+
return paths unless subpath
|
33
|
+
|
34
|
+
subpath = subpath.collect(&:dup)
|
35
|
+
offset = subpath.last.offset
|
36
|
+
paths.last.steps.concat subpath.shift.steps
|
37
|
+
paths.concat subpath
|
38
|
+
paths.last.instance_variable_set :@offset, offset
|
39
|
+
|
40
|
+
paths
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
23
44
|
def initialize(paths=[])
|
24
45
|
@paths = paths
|
25
46
|
end
|
@@ -133,40 +154,16 @@ module EPUB
|
|
133
154
|
class Range < ::Range
|
134
155
|
attr_accessor :parent_path, :start_subpath, :end_subpath
|
135
156
|
|
136
|
-
# @todo consider the case subpaths are redirected path
|
137
|
-
# @todo FIXME: too dirty
|
138
157
|
class << self
|
139
158
|
def from_parent_and_start_and_end(parent_path, start_subpath, end_subpath)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
first_paths = parent_path.collect(&:dup)
|
144
|
-
if start_subpath
|
145
|
-
offset_of_first = start_subpath.last.offset
|
146
|
-
offset_of_first = offset_of_first.dup if offset_of_first
|
147
|
-
last_of_first_paths = first_paths.pop
|
148
|
-
first_paths << last_of_first_paths
|
149
|
-
last_of_first_paths.steps.concat start_subpath.shift.steps
|
150
|
-
first_paths.concat start_subpath
|
151
|
-
first_paths.last.instance_variable_set :@offset, offset_of_first
|
152
|
-
end
|
153
|
-
offset_of_last = end_subpath.last.offset
|
154
|
-
offset_of_last = offset_of_last.dup if offset_of_last
|
155
|
-
last_paths = parent_path.collect(&:dup)
|
156
|
-
last_of_last_paths = last_paths.pop
|
157
|
-
last_paths << last_of_last_paths
|
158
|
-
last_of_last_paths.steps.concat end_subpath.shift.steps
|
159
|
-
last_paths.concat end_subpath
|
160
|
-
last_paths.last.instance_variable_set :@offset, offset_of_last
|
161
|
-
|
162
|
-
first = CFI::Location.new(first_paths)
|
163
|
-
last = CFI::Location.new(last_paths)
|
159
|
+
first = Location.from_parent_and_subpath(parent_path, start_subpath)
|
160
|
+
last = Location.from_parent_and_subpath(parent_path, end_subpath)
|
164
161
|
|
165
162
|
new_range = new(first, last)
|
166
163
|
|
167
164
|
new_range.parent_path = Location.new(parent_path)
|
168
|
-
new_range.start_subpath =
|
169
|
-
new_range.end_subpath =
|
165
|
+
new_range.start_subpath = start_subpath.join("!")
|
166
|
+
new_range.end_subpath = end_subpath.join("!")
|
170
167
|
|
171
168
|
new_range
|
172
169
|
end
|
data/lib/epub/cfi/version.rb
CHANGED
data/test/test_cfi.rb
CHANGED
@@ -28,6 +28,9 @@ class TestCFI < Test::Unit::TestCase
|
|
28
28
|
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:0)',
|
29
29
|
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:0)',
|
30
30
|
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3)',
|
31
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[iframe01]!/4/6,:6,/8:1)',
|
32
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[iframe01],!/4/6:6,/8:1)',
|
33
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[iframe01],/4!/4/6:6,/8:1)',
|
31
34
|
].reduce({}) {|data, cfi|
|
32
35
|
data[cfi] = cfi
|
33
36
|
data
|
data/test/test_parser.rb
CHANGED
@@ -27,7 +27,10 @@ class TestParserCFI < Test::Unit::TestCase
|
|
27
27
|
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3)',
|
28
28
|
'epubcfi(/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4)',
|
29
29
|
'epubcfi(/6,:1,:3)',
|
30
|
-
'epubcfi(/6/4[chap01ref]!/4[body01]/10[mov01]~23.5@5.75:97.6)'
|
30
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[mov01]~23.5@5.75:97.6)',
|
31
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[iframe01]!/4/6,:6,/8:1)',
|
32
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[iframe01],!/4/6:6,/8:1)',
|
33
|
+
'epubcfi(/6/4[chap01ref]!/4[body01]/10[iframe01],/4!/4/6:6,/8:1)',
|
31
34
|
].reduce({}) {|data, cfi|
|
32
35
|
data[cfi] = cfi
|
33
36
|
data
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epub-cfi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: racc
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.6.
|
168
|
+
rubygems_version: 2.6.13
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: EPUB CFI parser and builder
|