epub-parser 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'thin'
29
29
  s.add_development_dependency 'yard'
30
30
  s.add_development_dependency 'epzip'
31
+ s.add_development_dependency 'epub_validator'
31
32
 
32
33
  s.add_runtime_dependency 'enumerabler'
33
34
  s.add_runtime_dependency 'nokogiri'
@@ -0,0 +1,52 @@
1
+ require 'epub/ocf'
2
+ require 'epub/publication'
3
+ require 'epub/content_document'
4
+
5
+ module EPUB
6
+ modules = [ :ocf, :package, :content_document ]
7
+ attr_reader *modules
8
+ modules.each do |mod|
9
+ define_method "#{mod}=" do |obj|
10
+ instance_variable_set "@#{mod}", obj
11
+ obj.book = self
12
+ end
13
+ end
14
+
15
+ def each_page_by_spine(&blk)
16
+ enum = @package.spine.items
17
+ if block_given?
18
+ enum.each &blk
19
+ else
20
+ enum
21
+ end
22
+ end
23
+
24
+ def each_page_by_toc(&blk)
25
+ end
26
+
27
+ def each_content(&blk)
28
+ enum = @package.manifest.items
29
+ if block_given?
30
+ enum.each &blk
31
+ else
32
+ enum.to_enum
33
+ end
34
+ end
35
+
36
+ def other_navigation
37
+ end
38
+
39
+ def resources
40
+ @package.manifest.items
41
+ end
42
+
43
+ # Syntax sugar
44
+ def rootfile_path
45
+ ocf.container.rootfile.full_path
46
+ end
47
+
48
+ # Syntax sugar
49
+ def cover_image
50
+ package.manifest.cover_image
51
+ end
52
+ end
@@ -1,43 +1,7 @@
1
- require 'epub/ocf'
2
- require 'epub/publication'
3
- require 'epub/content_document'
1
+ require 'epub'
4
2
 
5
3
  module EPUB
6
4
  class Book
7
- attr_accessor :ocf, :package, :content_document
8
-
9
- def each_page_by_spine(&blk)
10
- enum = @package.spine.items
11
- if block_given?
12
- enum.each &blk
13
- else
14
- enum
15
- end
16
- end
17
-
18
- def each_page_by_toc(&blk)
19
- end
20
-
21
- def each_content(&blk)
22
- enum = @package.manifest.items
23
- if block_given?
24
- enum.each &blk
25
- else
26
- enum.to_enum
27
- end
28
- end
29
-
30
- def other_navigation
31
- end
32
-
33
- # Syntax sugar
34
- def rootfile_path
35
- ocf.container.rootfile.full_path
36
- end
37
-
38
- # Syntax sugar
39
- def cover_image
40
- package.manifest.cover_image
41
- end
5
+ include EPUB
42
6
  end
43
7
  end
@@ -3,6 +3,6 @@ module EPUB
3
3
  MODULES = %w[container encryption manifest metadata rights signatures]
4
4
  MODULES.each {|m| require "epub/ocf/#{m}"}
5
5
 
6
- attr_accessor *MODULES
6
+ attr_accessor :book, *MODULES
7
7
  end
8
8
  end
@@ -1,4 +1,3 @@
1
- require 'epub/book'
2
1
  require 'epub/constants'
3
2
  require 'epub/parser/version'
4
3
  require 'epub/parser/ocf'
@@ -23,7 +22,7 @@ module EPUB
23
22
  Dir.mkdir(root_directory) unless File.directory? root_directory
24
23
  @dir = File.realpath root_directory
25
24
 
26
- @book = Book.new
25
+ @book = create_book options
27
26
 
28
27
  unzip_cmd = options['unzip-command'] || 'unzip'
29
28
  unzip_cmd << " #{@filepath.to_s.shellescape} -d #{@dir.to_s.shellescape}"
@@ -34,7 +33,7 @@ puts unzip_cmd
34
33
  def parse
35
34
  @book.ocf = parse_ocf
36
35
  @book.package = parse_publication
37
- @book.content_document = parse_content_document
36
+ # @book.content_document =??? parse_content_document
38
37
  # ...
39
38
 
40
39
  @book
@@ -51,5 +50,19 @@ puts unzip_cmd
51
50
  def parse_content_document
52
51
  # ContentDocument.parse @dir
53
52
  end
53
+
54
+ private
55
+
56
+ def create_book(params)
57
+ case
58
+ when params[:book]
59
+ options[:book]
60
+ when params[:class]
61
+ options[:class].new
62
+ else
63
+ require 'epub/book'
64
+ Book.new
65
+ end
66
+ end
54
67
  end
55
68
  end
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  class Parser
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -3,7 +3,8 @@
3
3
  module EPUB
4
4
  module Publication
5
5
  class Package
6
- attr_accessor :version, :unique_identifier, :prefix, :xml_lang, :dir, :id
6
+ attr_accessor :book,
7
+ :version, :unique_identifier, :prefix, :xml_lang, :dir, :id
7
8
  attr_reader :metadata, :manifest, :spine, :guide
8
9
  alias lang xml_lang
9
10
  alias lang= xml_lang=
@@ -5,5 +5,3 @@ end
5
5
 
6
6
  gem 'test-unit'
7
7
  require 'test/unit'
8
-
9
- include EPUB
@@ -25,13 +25,13 @@ class TestParser < Test::Unit::TestCase
25
25
 
26
26
  def test_each_page_by_spine_iterates_items_in_spines_order
27
27
  @book.each_page_by_spine do |page|
28
- assert_instance_of Publication::Package::Manifest::Item, page
28
+ assert_instance_of EPUB::Publication::Package::Manifest::Item, page
29
29
  end
30
30
  end
31
31
 
32
32
  def test_each_content_iterates_items_in_manifest
33
33
  @book.each_content do |page|
34
- assert_instance_of Publication::Package::Manifest::Item, page
34
+ assert_instance_of EPUB::Publication::Package::Manifest::Item, page
35
35
  end
36
36
  end
37
37
 
@@ -45,7 +45,13 @@ class TestParser < Test::Unit::TestCase
45
45
  contents = @book.each_content
46
46
 
47
47
  contents.each do |page|
48
- assert_instance_of Publication::Package::Manifest::Item, page
48
+ assert_instance_of EPUB::Publication::Package::Manifest::Item, page
49
+ end
50
+ end
51
+
52
+ def test_h
53
+ @book.resources.each do |item|
54
+ assert_instance_of EPUB::Publication::Package::Manifest::Item, item
49
55
  end
50
56
  end
51
57
  end
@@ -4,7 +4,7 @@ require 'epub/parser/content_document'
4
4
  class TestParserContentDocument < Test::Unit::TestCase
5
5
  def setup
6
6
  @dir = 'test/fixtures/book'
7
- @parser = Parser::ContentDocument.new @dir
7
+ @parser = EPUB::Parser::ContentDocument.new @dir
8
8
  end
9
9
 
10
10
  def test_parse_navigations
@@ -4,7 +4,7 @@ require 'epub/parser/ocf'
4
4
 
5
5
  class TestParserOCF < Test::Unit::TestCase
6
6
  def setup
7
- @parser = Parser::OCF.new 'test/fixtures/book'
7
+ @parser = EPUB::Parser::OCF.new 'test/fixtures/book'
8
8
  end
9
9
 
10
10
  def test_parse_container_can_find_primary_rootfile
@@ -4,7 +4,7 @@ require 'epub/parser/publication'
4
4
 
5
5
  class TestParserPublication < Test::Unit::TestCase
6
6
  def setup
7
- @parser = Parser::Publication.new 'test/fixtures/book/OPS/ルートファイル.opf'
7
+ @parser = EPUB::Parser::Publication.new 'test/fixtures/book/OPS/ルートファイル.opf'
8
8
  end
9
9
 
10
10
  class TestParseManifest < TestParserPublication
@@ -26,7 +26,7 @@ class TestParserPublication < Test::Unit::TestCase
26
26
  def test_fallback_attribute_of_item_should_be_item_object
27
27
  fallback = @manifest['manifest-item-2'].fallback
28
28
 
29
- assert_instance_of Publication::Package::Manifest::Item, fallback
29
+ assert_instance_of EPUB::Publication::Package::Manifest::Item, fallback
30
30
  assert_equal 'manifest-item-fallback', fallback.id
31
31
  end
32
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-03 00:00:00.000000000Z
12
+ date: 2012-01-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubygems-test
16
- requirement: &9485980 !ruby/object:Gem::Requirement
16
+ requirement: &23104020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *9485980
24
+ version_requirements: *23104020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &9485300 !ruby/object:Gem::Requirement
27
+ requirement: &23103420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *9485300
35
+ version_requirements: *23103420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &9483760 !ruby/object:Gem::Requirement
38
+ requirement: &23102800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *9483760
46
+ version_requirements: *23102800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: test-unit
49
- requirement: &9481540 !ruby/object:Gem::Requirement
49
+ requirement: &23101980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *9481540
57
+ version_requirements: *23101980
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &9480560 !ruby/object:Gem::Requirement
60
+ requirement: &23101360 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *9480560
68
+ version_requirements: *23101360
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thin
71
- requirement: &9479860 !ruby/object:Gem::Requirement
71
+ requirement: &23100660 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *9479860
79
+ version_requirements: *23100660
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &9479400 !ruby/object:Gem::Requirement
82
+ requirement: &23099840 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *9479400
90
+ version_requirements: *23099840
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: epzip
93
- requirement: &9065560 !ruby/object:Gem::Requirement
93
+ requirement: &23099100 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,21 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *9065560
101
+ version_requirements: *23099100
102
+ - !ruby/object:Gem::Dependency
103
+ name: epub_validator
104
+ requirement: &23098420 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *23098420
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: enumerabler
104
- requirement: &9064540 !ruby/object:Gem::Requirement
115
+ requirement: &23114140 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :runtime
111
122
  prerelease: false
112
- version_requirements: *9064540
123
+ version_requirements: *23114140
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: nokogiri
115
- requirement: &9063520 !ruby/object:Gem::Requirement
126
+ requirement: &23113600 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: '0'
121
132
  type: :runtime
122
133
  prerelease: false
123
- version_requirements: *9063520
134
+ version_requirements: *23113600
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: addressable
126
- requirement: &9062780 !ruby/object:Gem::Requirement
137
+ requirement: &23113100 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,7 +142,7 @@ dependencies:
131
142
  version: '0'
132
143
  type: :runtime
133
144
  prerelease: false
134
- version_requirements: *9062780
145
+ version_requirements: *23113100
135
146
  description: Parse EPUB 3 book loosely
136
147
  email:
137
148
  - KitaitiMakoto@gmail.com
@@ -146,6 +157,7 @@ files:
146
157
  - README
147
158
  - Rakefile
148
159
  - epub-parser.gemspec
160
+ - lib/epub.rb
149
161
  - lib/epub/book.rb
150
162
  - lib/epub/constants.rb
151
163
  - lib/epub/content_document.rb
@@ -198,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
210
  version: '0'
199
211
  segments:
200
212
  - 0
201
- hash: 1208319521840117348
213
+ hash: 1759315474015504497
202
214
  required_rubygems_version: !ruby/object:Gem::Requirement
203
215
  none: false
204
216
  requirements:
@@ -207,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
219
  version: '0'
208
220
  segments:
209
221
  - 0
210
- hash: 1208319521840117348
222
+ hash: 1759315474015504497
211
223
  requirements: []
212
224
  rubyforge_project:
213
225
  rubygems_version: 1.8.8