epub-cfi 0.1.1 → 0.1.2

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
- SHA1:
3
- metadata.gz: bdbce4ceaf9a43a511b16ea3919f1f0f028eedbf
4
- data.tar.gz: fbb26bf902a5b301fa041bbe1d251bc33c840d7e
2
+ SHA256:
3
+ metadata.gz: c7bd4bcf31dae58b934393de702fb036186b950bbeb72d065931d0406506c2be
4
+ data.tar.gz: 5820d5272ed8c29790c69e959c1e4b140eae9e567182b2c5929dbbcff41efc0e
5
5
  SHA512:
6
- metadata.gz: 450c3498f4bc08da4fc5159239fb95e13ecdce20c22175a1d7be35a8390aef947097005a5a8b5bc09e3944d2c53a9f280b764e669f6b3cb3a4a8df8af690e923
7
- data.tar.gz: 781bb732392cfcc3c287465d6e2489ecaa6d6ec1a779f4443bf22416e93839a0a9b54bbc8adbf67347d24f00d7c842d073f2da8d520af68900441459bbd32f58
6
+ metadata.gz: 83d606fc2a8321349c6b055df31610bbc384b7c42e620ee01ec6b1461b2c6a51534327c70442894a70f8faf6c0cee0a0506e84b55c5765a25a97d2ae6548ac7e
7
+ data.tar.gz: 8b950b018d6bde45b2c1107ab2c19048c4e05e06cc49c4cd59c4c77a5b4b706228bc2268b65eebbb91314a51104b5fa48ddf5371c202c187bda1faf023fbccab
data/.document CHANGED
@@ -1,3 +1,3 @@
1
1
  -
2
- ChangeLog.md
2
+ ChangeLog.adoc
3
3
  COPYING.txt
@@ -1,12 +1,7 @@
1
1
  before_script:
2
2
  - ruby -v
3
3
  - which ruby
4
- - gem install racc rake rubygems-tasks yard test-unit test-unit-notify pretty_backtrace simplecov
5
-
6
- test:2.2:
7
- image: ruby:2.2
8
- script:
9
- rake test
4
+ - gem install --no-document racc rake rubygems-tasks yard test-unit test-unit-notify pretty_backtrace simplecov
10
5
 
11
6
  test:2.3:
12
7
  image: ruby:2.3
@@ -17,3 +12,13 @@ test:2.4:
17
12
  image: ruby:2.4
18
13
  script:
19
14
  rake test
15
+
16
+ test:2.5:
17
+ image: ruby:2.5
18
+ script:
19
+ rake test
20
+
21
+ test:2.6:
22
+ image: ruby:2.6
23
+ script:
24
+ rake test
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title "EPUB CFI Documentation" --protected
1
+ --markup asciidoc --title "EPUB CFI Documentation" --protected
@@ -1,9 +1,14 @@
1
- ### 0.1.1 / 2017-09-17
1
+ === 0.1.2 / 2019-05-19
2
+
3
+ * Scan CFI string on demand to reduce memory footprint
4
+ * Make CFI() funciton accepts CFI instance
5
+
6
+ === 0.1.1 / 2017-09-17
2
7
 
3
8
  * Add `CFI::Location.from_parent_and_subpath`
4
9
  * [BUG FIX]Consider the case subpath includes step indirection in Range.from_parent_and_start_and_end
5
10
 
6
- ### 0.1.0 / 2017-03-12
11
+ === 0.1.0 / 2017-03-12
7
12
 
8
13
  * Initial release:
9
14
 
@@ -0,0 +1,80 @@
1
+ = EPUB CFI
2
+
3
+ image:https://badge.fury.io/rb/epub-cfi.svg["Gem Version", link="https://badge.fury.io/rb/epub-cfi"]
4
+ image:https://gitlab.com/KitaitiMakoto/epub-cfi/badges/master/pipeline.svg[link="https://gitlab.com/KitaitiMakoto/epub-cfi/commits/master",title="pipeline status"]
5
+ image:https://gitlab.com/KitaitiMakoto/epub-cfi/badges/master/coverage.svg[link="https://gitlab.com/KitaitiMakoto/epub-cfi/commits/master",title="coverage report"]
6
+
7
+ * https://gitlab.com/KitaitiMakoto/epub-cfi[Homepage]
8
+ * http://rubydoc.info/gems/epub-cfi/frames[Documentation]
9
+ * mailto:KitaitiMakoto+at+gmail.com[Email]
10
+
11
+ == Description
12
+
13
+ Parser and builder implementation for EPUB CFI defined at http://www.idpf.org/epub/linking/cfi/
14
+
15
+ Extracted from http://www.rubydoc.info/gems/epub-parser/file/docs/Home.markdown[EPUB Parser].
16
+
17
+ == Features
18
+
19
+ * Parses EPUB CFI string.
20
+ * Builds EPUB CFI(implemented but currently useless).
21
+ * Converts EPUB CFI object to a string.
22
+
23
+ == Examples
24
+
25
+ ----
26
+ require 'epub/cfi'
27
+
28
+ location = EPUB::CFI.parse("epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])")
29
+ # Or location = EPUB::CFI("epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])")
30
+ # => #<EPUB::CFI::Location:/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]>
31
+ location.to_s # => "epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])"
32
+
33
+ location1 = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]")
34
+ location2 = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]")
35
+ location1 < location2 # => true
36
+ location1 <=> location2 # => -1
37
+ # location1 appears earlier than location2
38
+
39
+ range = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4")
40
+ # => #<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>
41
+ range.kind_of? ::Range # => true
42
+ range.begin
43
+ # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:1>
44
+ range.end
45
+ # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/3:4>
46
+ range.start_subpath
47
+ # => "/2/1:1"
48
+ range.end_subpath
49
+ # => "/3:4"
50
+ range.parent_path
51
+ # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]>
52
+ range.to_s # => "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4)"
53
+
54
+ builtin_range = location2..location1
55
+ # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]>..#<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]>
56
+ builtin_range.to_s
57
+ # => "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy])..epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y])"
58
+ builtin_range.kind_of? ::Range # => true
59
+ builtin_range.kind_of? EPUB::CFI::Range # => false
60
+ cfi_range = EPUB::CFI::Range.new(location2, location1)
61
+ # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]>..#<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]>
62
+ cfi_range.kind_of? ::Range # => true
63
+ cfi_range.kind_of? EPUB::CFI::Range # => true
64
+ ----
65
+
66
+ == Install
67
+
68
+ [listing]
69
+ $ gem install epub-cfi
70
+
71
+ == See also
72
+
73
+ * http://www.idpf.org/epub/linking/cfi/[EPUB Canonical Fragment Identifiers 1.1]
74
+ * http://www.rubydoc.info/gems/epub-parser/file/docs/Home.markdown[EPUB Parser]
75
+
76
+ == Copyright
77
+
78
+ Copyright (c) 2017 KITAITI Makoto
79
+
80
+ See {file:COPYING.txt} for details.
data/Rakefile CHANGED
@@ -3,16 +3,17 @@ require 'rake'
3
3
 
4
4
  task :default => "lib/epub/cfi/parser.tab.rb"
5
5
 
6
- file "lib/epub/cfi/parser.tab.rb" do |target|
7
- sh "racc #{target.name.sub("tab.rb", "y")}"
6
+ desc "Build EPUB CFI parser"
7
+ file "lib/epub/cfi/parser.tab.rb" => "lib/epub/cfi/parser.y" do |task|
8
+ sh "racc #{task.source}"
8
9
  end
9
10
 
10
11
  require "rake/clean"
11
- CLEAN.include "lib/epub/cfi/parser.tab.rb"
12
+ CLOBBER.include "lib/epub/cfi/parser.tab.rb"
12
13
 
13
14
  require 'rubygems/tasks'
14
15
  Gem::Tasks.new
15
- task :build => [:clean, "lib/epub/cfi/parser.tab.rb"]
16
+ task :build => "lib/epub/cfi/parser.tab.rb"
16
17
 
17
18
  require 'rake/testtask'
18
19
  Rake::TestTask.new do |test|
@@ -24,4 +25,3 @@ task :test => "lib/epub/cfi/parser.tab.rb"
24
25
 
25
26
  require 'yard'
26
27
  YARD::Rake::YardocTask.new
27
- task :doc => :yard
@@ -0,0 +1,21 @@
1
+ version: 1.0.{build}-{branch}
2
+
3
+ environment:
4
+ matrix:
5
+ - RUBY_VERSION: 23
6
+ - RUBY_VERSION: 24
7
+ - RUBY_VERSION: 25
8
+ - RUBY_VERSION: 26
9
+
10
+ install:
11
+ - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
12
+ - gem install --no-document racc rake rubygems-tasks yard test-unit test-unit-notify pretty_backtrace simplecov
13
+
14
+ build: off
15
+
16
+ before_test:
17
+ - ruby -v
18
+ - gem -v
19
+
20
+ test_script:
21
+ - rake test
@@ -6,15 +6,30 @@ module EPUB
6
6
  RE_ESCAPED_SPECIAL_CHARS = Regexp.escape(SPECIAL_CHARS)
7
7
 
8
8
  class << self
9
+ # Escapes special characters in string
10
+ #
11
+ # @example
12
+ # EPUB::CFI.escape("2[1]") #=> "2^[1^]"
13
+ #
14
+ # @param string [String] Component string of EPUB CFI
15
+ # @return [String] Escaped comonent string
9
16
  def escape(string)
10
17
  string.gsub(/([#{RE_ESCAPED_SPECIAL_CHARS}])/o, '^\1')
11
18
  end
12
19
 
20
+ # Unescape escaped characters in string
21
+ #
22
+ # @example
23
+ # EPUB::CFI.unescape("2^[1^]") #=> "2[1]"
24
+ #
25
+ # @param string [String] Escape component string of EPUB CFI
26
+ # @return [String] Unescaped component string
13
27
  def unescape(string)
14
28
  string.gsub(/\^([#{RE_ESCAPED_SPECIAL_CHARS}])/o, '\1')
15
29
  end
16
30
  end
17
31
 
32
+ # {Location} indicates a point in an EPUB Publication.
18
33
  class Location
19
34
  include Comparable
20
35
 
@@ -141,14 +156,6 @@ module EPUB
141
156
  end
142
157
  end
143
158
  end
144
-
145
- def each_step_with_instruction
146
- yield [step, nil]
147
- local_path.each_step_with_instruction do |s, instruction|
148
- yield [s, instruction]
149
- end
150
- self
151
- end
152
159
  end
153
160
 
154
161
  class Range < ::Range
@@ -7,12 +7,12 @@ class EPUB::CFI::Parser
7
7
  UNICODE_CHARACTER_PATTERN = Regexp.union(UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK_PATTERN, Regexp.new(Regexp.escape(EPUB::CFI::SPECIAL_CHARS), / \.:~@!/))
8
8
 
9
9
  class << self
10
- def parse(string, debug: false)
10
+ def parse(string, debug: $DEBUG)
11
11
  new(debug: debug).parse(string)
12
12
  end
13
13
  end
14
14
 
15
- def initialize(debug: false)
15
+ def initialize(debug: $DEBUG)
16
16
  @yydebug = debug
17
17
  super()
18
18
  end
@@ -22,67 +22,92 @@ class EPUB::CFI::Parser
22
22
  string = string['epubcfi('.length .. -2]
23
23
  end
24
24
  @scanner = StringScanner.new(string, true)
25
- @q = []
26
- until @scanner.eos?
27
- case
28
- when @scanner.scan(/[1-9]/)
29
- @q << [:DIGIT_NON_ZERO, @scanner[0]]
30
- when @scanner.scan(/0/)
31
- @q << [:ZERO, @scanner[0]]
32
- when @scanner.scan(/ /)
33
- @q << [:SPACE, @scanner[0]]
34
- when @scanner.scan(/\^/)
35
- @q << [:CIRCUMFLEX, @scanner[0]]
36
- when @scanner.scan(/\[/)
37
- @q << [:OPENING_SQUARE_BRACKET, @scanner[0]]
38
- when @scanner.scan(/\]/)
39
- @q << [:CLOSING_SQUARE_BRACKET, @scanner[0]]
40
- when @scanner.scan(/\(/)
41
- @q << [:OPENING_PARENTHESIS, @scanner[0]]
42
- when @scanner.scan(/\)/)
43
- @q << [:CLOSING_PARENTHESIS, @scanner[0]]
44
- when @scanner.scan(/,/)
45
- @q << [:COMMA, @scanner[0]]
46
- when @scanner.scan(/;/)
47
- @q << [:SEMICOLON, @scanner[0]]
48
- when @scanner.scan(/=/)
49
- @q << [:EQUAL, @scanner[0]]
50
- when @scanner.scan(/\./)
51
- @q << [:DOT, @scanner[0]]
52
- when @scanner.scan(/:/)
53
- @q << [:COLON, @scanner[0]]
54
- when @scanner.scan(/~/)
55
- @q << [:TILDE, @scanner[0]]
56
- when @scanner.scan(/@/)
57
- @q << [:ATMARK, @scanner[0]]
58
- when @scanner.scan(/\//)
59
- @q << [:SOLIDUS, @scanner[0]]
60
- when @scanner.scan(/!/)
61
- @q << [:EXCLAMATION_MARK, @scanner[0]]
62
- when @scanner.scan(UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK_PATTERN)
63
- @q << [:UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK, @scanner[0]]
64
- else
65
- raise 'unexpected character'
66
- end
67
- end
68
- @q << [false, false]
69
-
70
25
  do_parse
71
26
  end
72
27
 
73
28
  def next_token
74
- @q.shift
29
+ return [false, false] if @scanner.eos?
30
+
31
+ case
32
+ when @scanner.scan(/[1-9]/)
33
+ [:DIGIT_NON_ZERO, @scanner[0]]
34
+ when @scanner.scan(/0/)
35
+ [:ZERO, @scanner[0]]
36
+ when @scanner.scan(/ /)
37
+ [:SPACE, @scanner[0]]
38
+ when @scanner.scan(/\^/)
39
+ [:CIRCUMFLEX, @scanner[0]]
40
+ when @scanner.scan(/\[/)
41
+ [:OPENING_SQUARE_BRACKET, @scanner[0]]
42
+ when @scanner.scan(/\]/)
43
+ [:CLOSING_SQUARE_BRACKET, @scanner[0]]
44
+ when @scanner.scan(/\(/)
45
+ [:OPENING_PARENTHESIS, @scanner[0]]
46
+ when @scanner.scan(/\)/)
47
+ [:CLOSING_PARENTHESIS, @scanner[0]]
48
+ when @scanner.scan(/,/)
49
+ [:COMMA, @scanner[0]]
50
+ when @scanner.scan(/;/)
51
+ [:SEMICOLON, @scanner[0]]
52
+ when @scanner.scan(/=/)
53
+ [:EQUAL, @scanner[0]]
54
+ when @scanner.scan(/\./)
55
+ [:DOT, @scanner[0]]
56
+ when @scanner.scan(/:/)
57
+ [:COLON, @scanner[0]]
58
+ when @scanner.scan(/~/)
59
+ [:TILDE, @scanner[0]]
60
+ when @scanner.scan(/@/)
61
+ [:ATMARK, @scanner[0]]
62
+ when @scanner.scan(/\//)
63
+ [:SOLIDUS, @scanner[0]]
64
+ when @scanner.scan(/!/)
65
+ [:EXCLAMATION_MARK, @scanner[0]]
66
+ when @scanner.scan(UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK_PATTERN)
67
+ [:UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK, @scanner[0]]
68
+ else
69
+ raise 'unexpected character'
70
+ end
75
71
  end
76
72
  end
77
73
 
78
74
  module EPUB::CFI
79
75
  module_function
80
76
 
77
+ # Parses the given string, creates a new {CFI} object and return it.
78
+ #
79
+ # @example Parses a URI fragment string
80
+ # EPUB::CFI.parse("epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])")
81
+ # #=> #<EPUB::CFI::Location:/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]>
82
+ #
83
+ # @example Parses a path string
84
+ # EPUB::CFI.parse("/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]")
85
+ # #=> #<EPUB::CFI::Location:/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]>
86
+ #
87
+ # @param string [String]
88
+ # @return [CFI]
89
+ # @raise [Racc::ParseError] if given string is invalid
81
90
  def parse(string)
82
91
  EPUB::CFI::Parser.parse(string)
83
92
  end
84
93
  end
85
94
 
95
+ # Creates a new {CFI} object from the given string and return it.
96
+ #
97
+ # @example Creates from a URI fragment string
98
+ # EPUB::CFI("epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])")
99
+ # #=> #<EPUB::CFI::Location:/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]>
100
+ #
101
+ # @example Creates from a path string
102
+ # EPUB::CFI("/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]")
103
+ # #=> #<EPUB::CFI::Location:/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]>
104
+ #
105
+ # @param string [String, CFI]
106
+ # @return [CFI] CFI parsed from +string+ when +string+ is a String. +string+ itself when it's a CFI
107
+ # @raise [Racc::ParseError] if given string is invalid
108
+ # @see CFI.parse
86
109
  def EPUB::CFI(string)
87
- EPUB::CFI.parse(string)
110
+ string.kind_of?(EPUB::CFI::Location) || string.kind_of?(EPUB::CFI::Range) ?
111
+ string :
112
+ EPUB::CFI.parse(string)
88
113
  end
@@ -18,6 +18,6 @@
18
18
  module EPUB
19
19
  module CFI
20
20
  # epub-cfi version
21
- VERSION = "0.1.1"
21
+ VERSION = "0.1.2"
22
22
  end
23
23
  end
@@ -11,6 +11,28 @@ class TestCFI < Test::Unit::TestCase
11
11
  assert_equal '^[](),;=', EPUB::CFI.unescape('^^^[^]^(^)^,^;^=')
12
12
  end
13
13
 
14
+ class TestLocation < self
15
+ def test_copy
16
+ cfi = EPUB::CFI::Parser.parse('epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])')
17
+ cloned = cfi.clone
18
+ assert_equal cfi, cloned
19
+ assert_not_same cfi, cloned
20
+ end
21
+
22
+ def test_join
23
+ location = EPUB::CFI::Parser.parse('epubcfi(/6/14[chap05ref])')
24
+ other_path = EPUB::CFI::Path.new([EPUB::CFI::Path.new([
25
+ EPUB::CFI::Step.new(4, EPUB::CFI::IDAssertion.new('body01')),
26
+ EPUB::CFI::Step.new(10),
27
+ EPUB::CFI::Step.new(2),
28
+ EPUB::CFI::Step.new(1)
29
+ ])])
30
+ joined = location.join([other_path])
31
+
32
+ assert_equal 'epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1)', joined.to_s
33
+ end
34
+ end
35
+
14
36
  class TestPath < self
15
37
  data([
16
38
  'epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])',
@@ -53,4 +53,15 @@ class TestParserCFI < Test::Unit::TestCase
53
53
  EPUB::CFI(cfi)
54
54
  end
55
55
  end
56
+
57
+ def test_cfi_function_accepts_cfi_instance
58
+ cfi = EPUB::CFI::Parser.parse('epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])')
59
+ parsed = nil
60
+
61
+ assert_nothing_raised do
62
+ parsed = EPUB::CFI(cfi)
63
+ end
64
+
65
+ assert_equal cfi, parsed
66
+ end
56
67
  end
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.1
4
+ version: 0.1.2
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-09-16 00:00:00.000000000 Z
11
+ date: 2019-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: racc
@@ -133,9 +133,10 @@ files:
133
133
  - ".gitlab-ci.yml"
134
134
  - ".yardopts"
135
135
  - COPYING.txt
136
- - ChangeLog.md
137
- - README.md
136
+ - ChangeLog.adoc
137
+ - README.adoc
138
138
  - Rakefile
139
+ - appveyor.yml
139
140
  - epub-cfi.gemspec
140
141
  - lib/epub/cfi.rb
141
142
  - lib/epub/cfi/parser.rb
@@ -164,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  - !ruby/object:Gem::Version
165
166
  version: '0'
166
167
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.6.13
168
+ rubygems_version: 3.0.3
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: EPUB CFI parser and builder
data/README.md DELETED
@@ -1,85 +0,0 @@
1
- EPUB CFI
2
- ========
3
-
4
- * [Homepage](https://gitlab.com/KitaitiMakoto/epub-cfi)
5
- * [Documentation](http://rubydoc.info/gems/epub-cfi/frames)
6
- * [Email](mailto:KitaitiMakoto at gmail.com)
7
-
8
- Description
9
- -----------
10
-
11
- Parser and builder implementation for EPUB CFI defined at http://www.idpf.org/epub/linking/cfi/
12
-
13
- Extracted from [EPUB Parser][].
14
-
15
- [EPUB Parser]: http://www.rubydoc.info/gems/epub-parser/file/docs/Home.markdown
16
-
17
- Features
18
- --------
19
-
20
- * Parses EPUB CFI string.
21
- * Builds EPUB CFI(implemented but currently useless).
22
- * Converts EPUB CFI object to a string.
23
-
24
- Examples
25
- --------
26
-
27
- require 'epub/cfi'
28
-
29
- location = EPUB::CFI.parse("epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])")
30
- # Or location = EPUB::CFI("epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])")
31
- # => #<EPUB::CFI::Location:/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]]>
32
- location.to_s # => "epubcfi(/6/14[chap05ref]!/4[body01]/10/2/1:3[2^[1^]])"
33
-
34
- location1 = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]")
35
- location2 = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]")
36
- location1 < location2 # => true
37
- location1 <=> location2 # => -1
38
- # location1 appears earlier than location2
39
-
40
- range = EPUB::CFI("/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4")
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>
42
- range.kind_of? ::Range # => true
43
- range.begin
44
- # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:1>
45
- range.end
46
- # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/3:4>
47
- range.start_subpath
48
- # => "/2/1:1"
49
- range.end_subpath
50
- # => "/3:4"
51
- range.parent_path
52
- # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]>
53
- range.to_s # => "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4)"
54
-
55
- builtin_range = location2..location1
56
- # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]>..#<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]>
57
- builtin_range.to_s
58
- # => "epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy])..epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y])"
59
- builtin_range.kind_of? ::Range # => true
60
- builtin_range.kind_of? EPUB::CFI::Range # => false
61
- cfi_range = EPUB::CFI::Range.new(location2, location1)
62
- # => #<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3[yyy]>..#<EPUB::CFI::Location:/6/4[chap01ref]!/4[body01]/10[para05]/1:3[xx,y]>
63
- cfi_range.kind_of? ::Range # => true
64
- cfi_range.kind_of? EPUB::CFI::Range # => true
65
-
66
- Install
67
- -------
68
-
69
- $ gem install epub-cfi
70
-
71
- See also
72
- --------
73
-
74
- * [EPUB Canonical Fragment Identifiers 1.1][spec]
75
- * [EPUB Parser][]
76
-
77
- [spec]: http://www.idpf.org/epub/linking/cfi/
78
- [EPUB Parser]: http://www.rubydoc.info/gems/epub-parser/file/docs/Home.markdown
79
-
80
- Copyright
81
- ---------
82
-
83
- Copyright (c) 2017 KITAITI Makoto
84
-
85
- See {file:COPYING.txt} for details.