epubinfo 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.0
data/epubinfo.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "epubinfo"
8
- s.version = "0.2.4"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christof Dorner"]
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  "spec/lib/epubinfo_spec.rb",
43
43
  "spec/spec_helper.rb",
44
44
  "spec/support/binary/metamorphosis_epub2.epub",
45
+ "spec/support/binary/metamorphosis_epub2_drm.epub",
45
46
  "spec/support/binary/wasteland_epub3.epub",
46
47
  "spec/support/xml/metamorphosis_metadata_epub2.opf",
47
48
  "spec/support/xml/wasteland_metadata_epub3.opf"
@@ -4,39 +4,61 @@ module EPUBInfo
4
4
  # Titles, array of String instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.1 EPUB2 reference})
5
5
  # @return [Array]
6
6
  attr_accessor :titles
7
+
7
8
  # Creators, array of Person instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.2 EPUB2 reference})
8
9
  # @return [Array]
9
10
  attr_accessor :creators
11
+ def creators; @creators || []; end
12
+
10
13
  # Subjects, array of String instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.3 EPUB2 reference})
11
14
  # @return [Array]
12
15
  attr_accessor :subjects
16
+ def subjects; @subjects || []; end
17
+
13
18
  # Description ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.4 EPUB2 reference})
14
19
  # @return [String]
15
20
  attr_accessor :description
21
+
16
22
  # Publisher ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.5 EPUB2 reference})
17
23
  # @return [String]
18
24
  attr_accessor :publisher
25
+
19
26
  # Contributors, array of Person instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.6 EPUB2 reference})
20
27
  # @return [Array]
21
28
  attr_accessor :contributors
29
+ def contributors; @contributors || []; end
30
+
22
31
  # Dates, array of Date instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.7 EPUB2 reference})
23
32
  # @return [Array]
24
33
  attr_accessor :dates
34
+ def dates; @dates || []; end
35
+
25
36
  # Identifiers, array of Identifier instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.10 EPUB2 reference})
26
37
  # @return [Array]
27
38
  attr_accessor :identifiers
39
+ def identifiers; @identifiers || []; end
40
+
28
41
  # Source ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.11 EPUB2 reference})
29
42
  # @return [String]
30
43
  attr_accessor :source
44
+
31
45
  # Languages, array of String instances ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.12 EPUB2 reference})
32
46
  # @return [Array]
33
47
  attr_accessor :languages
48
+ def languages; @languages || []; end
49
+
34
50
  # Rights ({http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.15 EPUB2 reference})
35
51
  # @return [String]
36
52
  attr_accessor :rights
37
53
 
54
+ # DRM protected
55
+ # @return [Boolean]
56
+ attr_accessor :drm_protected
57
+ def drm_protected; @drm_protected || false; end
58
+ alias :drm_protected? :drm_protected
59
+
38
60
  # Should never be called directly, go through EPUBInfo.get
39
- def initialize(document)
61
+ def initialize(document, drm_protected = false)
40
62
  return if document.nil?
41
63
  metadata = document.css('metadata')
42
64
  self.titles = metadata.xpath('.//dc:title', EPUBInfo::Utils::DC_NAMESPACE).map(&:content)
@@ -50,15 +72,9 @@ module EPUBInfo
50
72
  self.source = metadata.xpath('.//dc:source', EPUBInfo::Utils::DC_NAMESPACE).first.content rescue nil
51
73
  self.languages = metadata.xpath('.//dc:language', EPUBInfo::Utils::DC_NAMESPACE).map(&:content)
52
74
  self.rights = metadata.xpath('.//dc:rights', EPUBInfo::Utils::DC_NAMESPACE).first.content rescue nil
75
+ self.drm_protected = drm_protected
53
76
  end
54
77
 
55
- def titles; @titles || []; end
56
- def creators; @creators || []; end
57
- def subjects; @subjects || []; end
58
- def contributors; @contributors || []; end
59
- def dates; @dates || []; end
60
- def identifiers; @identifiers || []; end
61
- def languages; @languages || []; end
62
78
 
63
79
  # Returns Hash representation of the book
64
80
  # @return [Hash]
@@ -74,7 +90,8 @@ module EPUBInfo
74
90
  :identifiers => @identifiers.map(&:to_hash),
75
91
  :source => @source,
76
92
  :languages => @languages,
77
- :rights => @rights
93
+ :rights => @rights,
94
+ :drm_protected => @drm_protected
78
95
  }
79
96
  end
80
97
  end
@@ -12,6 +12,11 @@ module EPUBInfo
12
12
  @metadata_document ||= load_metadata_file
13
13
  end
14
14
 
15
+ def drm_protected?
16
+ load_epub if @zipfile.nil?
17
+ @drm_protected ||= !!@zipfile.find_entry('META-INF/rights.xml')
18
+ end
19
+
15
20
  private
16
21
 
17
22
  def load_epub
data/lib/epubinfo.rb CHANGED
@@ -13,6 +13,6 @@ module EPUBInfo
13
13
  # @return [EPUBInfo::Models::Book] a model representation of the epub file
14
14
  def self.get(path)
15
15
  parser = EPUBInfo::Parser.parse(path)
16
- EPUBInfo::Models::Book.new(parser.metadata_document)
16
+ EPUBInfo::Models::Book.new(parser.metadata_document, parser.drm_protected?)
17
17
  end
18
18
  end
@@ -12,6 +12,7 @@ describe EPUBInfo::Models::Book do
12
12
  its(:source) { should == 'http://www.gutenberg.org/files/5200/5200-h/5200-h.htm' }
13
13
  its(:languages) { should == ['en'] }
14
14
  its(:rights) { should == 'Copyrighted. Read the copyright notice inside this book for details.' }
15
+ its(:drm_protected?) { should be_false }
15
16
 
16
17
  context 'creators' do
17
18
  it 'count should be 1' do
@@ -62,6 +62,33 @@ describe EPUBInfo::Parser do
62
62
  end
63
63
  end
64
64
 
65
+ describe '#drm_protected?' do
66
+ it 'should call load_epub if nil' do
67
+ zipfile_mock = mock(:find_entry => true)
68
+ parser.should_receive(:load_epub) { parser.instance_variable_set(:@zipfile, zipfile_mock); nil }
69
+ parser.drm_protected?
70
+ parser.instance_variable_get(:@zipfile).should == zipfile_mock
71
+ end
72
+
73
+ context 'drm' do
74
+ let(:epub_path) { File.expand_path('spec/support/binary/metamorphosis_epub2_drm.epub') }
75
+
76
+ it 'should return true if rights.xml exists' do
77
+ parser = EPUBInfo::Parser.parse(epub_path)
78
+ parser.drm_protected?.should be_true
79
+ end
80
+ end
81
+
82
+ context 'no drm' do
83
+ let(:epub_path) { File.expand_path('spec/support/binary/metamorphosis_epub2.epub') }
84
+
85
+ it 'should return false if rights.xml does not exist' do
86
+ parser = EPUBInfo::Parser.parse(epub_path)
87
+ parser.drm_protected?.should be_false
88
+ end
89
+ end
90
+ end
91
+
65
92
  describe '#load_metadata_file' do
66
93
  it 'should return xml document' do
67
94
  parser.send(:load_root_file)
@@ -8,6 +8,7 @@ describe EPUBInfo do
8
8
  document = EPUBInfo::Parser.parse(epub_path).metadata_document
9
9
  parser = mock
10
10
  parser.stub(:metadata_document)
11
+ parser.stub(:drm_protected?)
11
12
  EPUBInfo::Parser.should_receive(:parse) { parser }
12
13
  EPUBInfo.get(epub_path)
13
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epubinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
16
- requirement: &70180476902880 !ruby/object:Gem::Requirement
16
+ requirement: &70304125144560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70180476902880
24
+ version_requirements: *70304125144560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70180476901240 !ruby/object:Gem::Requirement
27
+ requirement: &70304125143040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.4.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70180476901240
35
+ version_requirements: *70304125143040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70180476899160 !ruby/object:Gem::Requirement
38
+ requirement: &70304125141680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.9.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70180476899160
46
+ version_requirements: *70304125141680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &70180476898380 !ruby/object:Gem::Requirement
49
+ requirement: &70304125140740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.7.5
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70180476898380
57
+ version_requirements: *70304125140740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &70180476897680 !ruby/object:Gem::Requirement
60
+ requirement: &70304125139680 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.1.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70180476897680
68
+ version_requirements: *70304125139680
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &70180476896740 !ruby/object:Gem::Requirement
71
+ requirement: &70304125138600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.8.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70180476896740
79
+ version_requirements: *70304125138600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70180476895960 !ruby/object:Gem::Requirement
82
+ requirement: &70304125137740 !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: *70180476895960
90
+ version_requirements: *70304125137740
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard
93
- requirement: &70180476895100 !ruby/object:Gem::Requirement
93
+ requirement: &70304125136420 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70180476895100
101
+ version_requirements: *70304125136420
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard-rspec
104
- requirement: &70180476893840 !ruby/object:Gem::Requirement
104
+ requirement: &70304125135240 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70180476893840
112
+ version_requirements: *70304125135240
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rb-fsevent
115
- requirement: &70180476891720 !ruby/object:Gem::Requirement
115
+ requirement: &70304125133980 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70180476891720
123
+ version_requirements: *70304125133980
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: growl
126
- requirement: &70180476885380 !ruby/object:Gem::Requirement
126
+ requirement: &70304125133220 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70180476885380
134
+ version_requirements: *70304125133220
135
135
  description: Supports EPUB2 and EPUB3 formats.
136
136
  email: christof@chdorner.com
137
137
  executables: []
@@ -165,6 +165,7 @@ files:
165
165
  - spec/lib/epubinfo_spec.rb
166
166
  - spec/spec_helper.rb
167
167
  - spec/support/binary/metamorphosis_epub2.epub
168
+ - spec/support/binary/metamorphosis_epub2_drm.epub
168
169
  - spec/support/binary/wasteland_epub3.epub
169
170
  - spec/support/xml/metamorphosis_metadata_epub2.opf
170
171
  - spec/support/xml/wasteland_metadata_epub3.opf
@@ -183,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
184
  version: '0'
184
185
  segments:
185
186
  - 0
186
- hash: 287389342377150280
187
+ hash: -524926705083524689
187
188
  required_rubygems_version: !ruby/object:Gem::Requirement
188
189
  none: false
189
190
  requirements: