epub-cfi 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8aca7ef76271077d0c4026b20d05df02926a9ca
4
- data.tar.gz: 14dabd7b660a4047585ffa63cb2ac31bd109125f
3
+ metadata.gz: bdbce4ceaf9a43a511b16ea3919f1f0f028eedbf
4
+ data.tar.gz: fbb26bf902a5b301fa041bbe1d251bc33c840d7e
5
5
  SHA512:
6
- metadata.gz: 8eb1f1a5a5a5ba3e6fca187ffcadad7b796bc0ea680b5a2ef5b2659a4c5ed95986b57593c9622a0450033d084e00cf3ef6bef36c9e73ea15cf2b80ab4a011502
7
- data.tar.gz: 213f294bb142f9ef4dd5402d0d3d8a702cdca7156d0cd7b298a0d0f512b1ac239593f9908b12d1b9235fc5b24205237c557308b81d8c702726c382104814b9d0
6
+ metadata.gz: 450c3498f4bc08da4fc5159239fb95e13ecdce20c22175a1d7be35a8390aef947097005a5a8b5bc09e3944d2c53a9f280b764e669f6b3cb3a4a8df8af690e923
7
+ data.tar.gz: 781bb732392cfcc3c287465d6e2489ecaa6d6ec1a779f4443bf22416e93839a0a9b54bbc8adbf67347d24f00d7c842d073f2da8d520af68900441459bbd32f58
@@ -1,3 +1,8 @@
1
+ ### 0.1.1 / 2017-09-17
2
+
3
+ * Add `CFI::Location.from_parent_and_subpath`
4
+ * [BUG FIX]Consider the case subpath includes step indirection in Range.from_parent_and_start_and_end
5
+
1
6
  ### 0.1.0 / 2017-03-12
2
7
 
3
8
  * Initial release:
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 <=> location1 # => -1
38
- # location2 appears earlier than location1
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>
@@ -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.add_runtime_dependency "racc"
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'
@@ -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
- start_str = start_subpath.join
141
- end_str = end_subpath.join
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 = start_str
169
- new_range.end_subpath = end_str
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
@@ -18,6 +18,6 @@
18
18
  module EPUB
19
19
  module CFI
20
20
  # epub-cfi version
21
- VERSION = "0.1.0"
21
+ VERSION = "0.1.1"
22
22
  end
23
23
  end
@@ -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
@@ -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.0
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-03-12 00:00:00.000000000 Z
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: :runtime
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.8
168
+ rubygems_version: 2.6.13
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: EPUB CFI parser and builder