epubinfo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.travis.yml +14 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +53 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/lib/epubinfo.rb +14 -0
- data/lib/epubinfo/models/book.rb +33 -0
- data/lib/epubinfo/models/date.rb +13 -0
- data/lib/epubinfo/models/identifier.rb +13 -0
- data/lib/epubinfo/models/person.rb +14 -0
- data/lib/epubinfo/parser.rb +36 -0
- data/spec/lib/epubinfo/identifier_spec.rb +9 -0
- data/spec/lib/epubinfo/models/book_spec.rb +76 -0
- data/spec/lib/epubinfo/models/date_spec.rb +8 -0
- data/spec/lib/epubinfo/models/person_spec.rb +20 -0
- data/spec/lib/epubinfo/parser_spec.rb +84 -0
- data/spec/lib/epubinfo_spec.rb +13 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/binary/metamorphosis.epub +0 -0
- data/spec/support/xml/metamorphosis_metadata.opf +32 -0
- metadata +195 -0
data/.document
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# ----------------------------------------------------------------
|
2
|
+
# Configuration file for http://travis-ci.org/#!/chdorner/epubinfo
|
3
|
+
# ----------------------------------------------------------------
|
4
|
+
|
5
|
+
language: ruby
|
6
|
+
script: "bundle exec rake spec"
|
7
|
+
rvm:
|
8
|
+
- 1.9.2
|
9
|
+
- 1.9.3
|
10
|
+
- ruby-head
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- gem install bundler
|
14
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rubyzip", "~> 0.9.6"
|
4
|
+
gem "nokogiri", "~> 1.5.2"
|
5
|
+
|
6
|
+
# Add dependencies required to use your gem here.
|
7
|
+
# Example:
|
8
|
+
# gem "activesupport", ">= 2.3.5"
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rspec", "~> 2.9.0"
|
14
|
+
gem "yard", "~> 0.7.5"
|
15
|
+
gem "bundler", "~> 1.1.3"
|
16
|
+
gem "jeweler", "~> 1.8.3"
|
17
|
+
gem "simplecov", ">= 0"
|
18
|
+
gem "guard"
|
19
|
+
gem "guard-rspec"
|
20
|
+
gem "rb-fsevent"
|
21
|
+
gem "growl"
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
growl (1.0.3)
|
7
|
+
guard (0.8.8)
|
8
|
+
thor (~> 0.14.6)
|
9
|
+
guard-rspec (0.5.2)
|
10
|
+
guard (>= 0.8.4)
|
11
|
+
jeweler (1.8.3)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rdoc
|
16
|
+
json (1.6.6)
|
17
|
+
multi_json (1.2.0)
|
18
|
+
nokogiri (1.5.2)
|
19
|
+
rake (0.9.2.2)
|
20
|
+
rb-fsevent (0.9.0)
|
21
|
+
rdoc (3.12)
|
22
|
+
json (~> 1.4)
|
23
|
+
rspec (2.9.0)
|
24
|
+
rspec-core (~> 2.9.0)
|
25
|
+
rspec-expectations (~> 2.9.0)
|
26
|
+
rspec-mocks (~> 2.9.0)
|
27
|
+
rspec-core (2.9.0)
|
28
|
+
rspec-expectations (2.9.0)
|
29
|
+
diff-lcs (~> 1.1.3)
|
30
|
+
rspec-mocks (2.9.0)
|
31
|
+
rubyzip (0.9.6.1)
|
32
|
+
simplecov (0.6.1)
|
33
|
+
multi_json (~> 1.0)
|
34
|
+
simplecov-html (~> 0.5.3)
|
35
|
+
simplecov-html (0.5.3)
|
36
|
+
thor (0.14.6)
|
37
|
+
yard (0.7.5)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.1.3)
|
44
|
+
growl
|
45
|
+
guard
|
46
|
+
guard-rspec
|
47
|
+
jeweler (~> 1.8.3)
|
48
|
+
nokogiri (~> 1.5.2)
|
49
|
+
rb-fsevent
|
50
|
+
rspec (~> 2.9.0)
|
51
|
+
rubyzip (~> 0.9.6)
|
52
|
+
simplecov
|
53
|
+
yard (~> 0.7.5)
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Christof Dorner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= epubinfo {<img src="https://secure.travis-ci.org/chdorner/epubinfo.png?branch=master" alt="Continuous Integration" />}[http://travis-ci.org/chdorner/epubinfo] {<img src="https://gemnasium.com/chdorner/epubinfo.png" alt="Dependencies" />}[http://gemnasium.com/chdorner/epubinfo]
|
2
|
+
|
3
|
+
Extracts metadata information from EPUB files. Currently only supports EPUB 2 specification.
|
4
|
+
|
5
|
+
== Contributing to epubinfo
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Christof Dorner. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "epubinfo"
|
18
|
+
gem.homepage = "http://github.com/chdorner/epubinfo"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Extracts metadata information from EPUB files}
|
21
|
+
gem.description = %Q{Currently only supports EPUB 3 specification.}
|
22
|
+
gem.email = "christof@chdorner.com"
|
23
|
+
gem.authors = ["Christof Dorner"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:spec)
|
30
|
+
|
31
|
+
task :default => :spec
|
32
|
+
|
33
|
+
require 'yard'
|
34
|
+
YARD::Rake::YardocTask.new do |t|
|
35
|
+
t.files = ['lib/**/*.rb', 'epubinfo.rb', '-', 'REAMDE.rdoc']
|
36
|
+
#t.options = ['--any', '--extra', '--opts']
|
37
|
+
end
|
38
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/epubinfo.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
require 'epubinfo/parser'
|
5
|
+
require 'epubinfo/models/book'
|
6
|
+
require 'epubinfo/models/person'
|
7
|
+
require 'epubinfo/models/date'
|
8
|
+
require 'epubinfo/models/identifier'
|
9
|
+
|
10
|
+
module EPUBInfo
|
11
|
+
def self.get(path)
|
12
|
+
parser = EPUBInfo::Parser.parse(path)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module EPUBInfo
|
2
|
+
module Models
|
3
|
+
class Book
|
4
|
+
attr_accessor :titles, :creators, :subjects, :description,
|
5
|
+
:publisher, :contributors, :dates, :identifiers,
|
6
|
+
:source, :languages, :rights
|
7
|
+
|
8
|
+
def initialize(document)
|
9
|
+
metadata = document.css('metadata')
|
10
|
+
self.titles = metadata.xpath('.//dc:title').map(&:content)
|
11
|
+
self.creators = metadata.xpath('.//dc:creator').map {|c| EPUBInfo::Models::Person.new(c) }
|
12
|
+
self.subjects = metadata.xpath('.//dc:subject').map(&:content)
|
13
|
+
self.description = metadata.xpath('.//dc:description').first.content rescue nil
|
14
|
+
self.publisher = metadata.xpath('.//dc:publisher').first.content rescue nil
|
15
|
+
self.contributors = metadata.xpath('.//dc:contributor').map {|c| EPUBInfo::Models::Person.new(c) }
|
16
|
+
self.dates = metadata.xpath('.//dc:date').map { |d| EPUBInfo::Models::Date.new(d) }
|
17
|
+
self.identifiers = metadata.xpath('.//dc:identifier').map { |i| EPUBInfo::Models::Identifier.new(i) }
|
18
|
+
self.source = metadata.xpath('.//dc:source').first.content rescue nil
|
19
|
+
self.languages = metadata.xpath('.//dc:language').map(&:content)
|
20
|
+
self.rights = metadata.xpath('.//dc:rights').first.content rescue nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def titles; @titles || []; end
|
24
|
+
def creators; @creators || []; end
|
25
|
+
def subjects; @subjects || []; end
|
26
|
+
def contributors; @contributors || []; end
|
27
|
+
def dates; @dates || []; end
|
28
|
+
def identifiers; @identifiers || []; end
|
29
|
+
def languages; @languages || []; end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module EPUBInfo
|
2
|
+
module Models
|
3
|
+
class Person
|
4
|
+
attr_accessor :name, :file_as, :role
|
5
|
+
|
6
|
+
def initialize(node)
|
7
|
+
self.name = node.content
|
8
|
+
self.file_as = node.attribute('file-as').content rescue nil
|
9
|
+
self.role = node.attribute('role').content rescue nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module EPUBInfo
|
2
|
+
class Parser
|
3
|
+
attr_accessor :path, :metadata_document
|
4
|
+
|
5
|
+
def self.parse(path)
|
6
|
+
epubinfo = EPUBInfo::Parser.new
|
7
|
+
epubinfo.path = path
|
8
|
+
epubinfo
|
9
|
+
end
|
10
|
+
|
11
|
+
def metadata_document
|
12
|
+
@metadata_document ||= load_metadata_file
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def load_epub
|
18
|
+
@zipfile = Zip::ZipFile.open(@path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_root_file
|
22
|
+
load_epub if @zipfile.nil?
|
23
|
+
@root_document = Nokogiri::XML(@zipfile.read('META-INF/container.xml'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def metadata_path
|
27
|
+
load_root_file if @root_document.nil?
|
28
|
+
@root_document.css('container rootfiles rootfile:first-child').attribute('full-path').content
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_metadata_file
|
32
|
+
load_epub if @zipfile.nil?
|
33
|
+
Nokogiri::XML(@zipfile.read(metadata_path))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EPUBInfo::Models::Identifier do
|
4
|
+
subject { EPUBInfo::Models::Identifier.new(Nokogiri::XML(File.new('spec/support/xml/metamorphosis_metadata.opf')).css('metadata').xpath('.//dc:identifier').first) }
|
5
|
+
|
6
|
+
its(:identifier) { should == 'http://www.gutenberg.org/ebooks/5200' }
|
7
|
+
its(:scheme) { should == 'URI' }
|
8
|
+
end
|
9
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EPUBInfo::Models::Book do
|
4
|
+
subject { EPUBInfo::Models::Book.new(Nokogiri::XML(File.new('spec/support/xml/metamorphosis_metadata.opf'))) }
|
5
|
+
|
6
|
+
its(:titles) { should == ['Metamorphosis'] }
|
7
|
+
its(:subjects) { should == ['Psychological fiction', 'Metamorphosis -- Fiction'] }
|
8
|
+
its(:description) { should == 'Classic story of self-discovery, told in a unique manner by Kafka.' }
|
9
|
+
its(:publisher) { should == 'Random House' }
|
10
|
+
#its(:date) { should == '' }
|
11
|
+
#its(:identifier) { should == '' }
|
12
|
+
its(:source) { should == 'http://www.gutenberg.org/files/5200/5200-h/5200-h.htm' }
|
13
|
+
its(:languages) { should == ['en'] }
|
14
|
+
its(:rights) { should == 'Copyrighted. Read the copyright notice inside this book for details.' }
|
15
|
+
|
16
|
+
context 'creators' do
|
17
|
+
it 'count should be 1' do
|
18
|
+
subject.creators.count.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'values should be of type Person' do
|
22
|
+
subject.creators.each do |creator|
|
23
|
+
creator.should be_kind_of EPUBInfo::Models::Person
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'contributors' do
|
29
|
+
it 'count should be 1' do
|
30
|
+
subject.contributors.count.should == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'values should be of type Person' do
|
34
|
+
subject.contributors.each do |contributor|
|
35
|
+
contributor.should be_kind_of EPUBInfo::Models::Person
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'dates' do
|
41
|
+
it 'count should be 1' do
|
42
|
+
subject.dates.count.should == 2
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'values should be of type Date' do
|
46
|
+
subject.dates.each do |date|
|
47
|
+
date.should be_kind_of EPUBInfo::Models::Date
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'identifiers' do
|
53
|
+
it 'count should be 1' do
|
54
|
+
subject.identifiers.count.should == 1
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'values should be of type Identifier' do
|
58
|
+
subject.identifiers.each do |identifier|
|
59
|
+
identifier.should be_kind_of EPUBInfo::Models::Identifier
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'default values' do
|
65
|
+
subject { EPUBInfo::Models::Book.new(Nokogiri::XML::Document.new) }
|
66
|
+
|
67
|
+
its(:titles) { should == [] }
|
68
|
+
its(:creators) { should == [] }
|
69
|
+
its(:subjects) { should == [] }
|
70
|
+
its(:contributors) { should == [] }
|
71
|
+
its(:dates) { should == [] }
|
72
|
+
its(:identifiers) { should == [] }
|
73
|
+
its(:languages) { should == [] }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EPUBInfo::Models::Date do
|
4
|
+
subject { EPUBInfo::Models::Date.new(Nokogiri::XML(File.new('spec/support/xml/metamorphosis_metadata.opf')).css('metadata').xpath('.//dc:date').first) }
|
5
|
+
|
6
|
+
its(:time) { should == Time.parse('2005-08-17') }
|
7
|
+
its(:event) { should == 'publication' }
|
8
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EPUBInfo::Models::Person do
|
4
|
+
context 'creator' do
|
5
|
+
subject { EPUBInfo::Models::Person.new(Nokogiri::XML(File.new('spec/support/xml/metamorphosis_metadata.opf')).css('metadata').xpath('.//dc:creator').first) }
|
6
|
+
|
7
|
+
its(:name) { should == 'Franz Kafka' }
|
8
|
+
its(:file_as) { should == 'Kafka, Franz' }
|
9
|
+
its(:role) { should be_nil }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'contributor' do
|
13
|
+
subject { EPUBInfo::Models::Person.new(Nokogiri::XML(File.new('spec/support/xml/metamorphosis_metadata.opf')).css('metadata').xpath('.//dc:contributor').first) }
|
14
|
+
|
15
|
+
its(:name) { should == 'David Wyllie' }
|
16
|
+
its(:file_as) { should == 'Wyllie, David' }
|
17
|
+
its(:role) { should == 'trl' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EPUBInfo::Parser do
|
4
|
+
let(:epub_path) { File.expand_path('spec/support/binary/metamorphosis.epub') }
|
5
|
+
let(:parser) { EPUBInfo::Parser.parse(epub_path) }
|
6
|
+
|
7
|
+
describe '#parse' do
|
8
|
+
it 'should assign path to @path' do
|
9
|
+
parser # preload to avoid infinite loop
|
10
|
+
EPUBInfo::Parser.stub(:new) { parser }
|
11
|
+
EPUBInfo::Parser.parse(epub_path)
|
12
|
+
parser.path.should == epub_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#load_epub' do
|
17
|
+
it 'assigns zipfile to @zipfile' do
|
18
|
+
parser.send(:load_epub)
|
19
|
+
parser.instance_variable_get(:@zipfile).should be_kind_of Zip::ZipFile
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#load_root_file' do
|
24
|
+
it 'should assign nokogiri document to @root_document' do
|
25
|
+
parser.send(:load_epub)
|
26
|
+
parser.send(:load_root_file)
|
27
|
+
parser.instance_variable_get(:@root_document).should be_kind_of Nokogiri::XML::Document
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should call load_epub if @zipfile is nil' do
|
31
|
+
zipfile = Zip::ZipFile.new(epub_path)
|
32
|
+
zipfile.stub(:read) { '' }
|
33
|
+
parser.should_receive(:load_epub) { parser.instance_variable_set(:@zipfile, zipfile); nil }
|
34
|
+
parser.send(:load_root_file)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#metadata_path' do
|
39
|
+
it 'should return path to metadata file' do
|
40
|
+
parser.send(:metadata_path).should == '5200/content.opf'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should call load_root_file if @root_document is nil' do
|
44
|
+
xml_document = Nokogiri::XML::Document.new
|
45
|
+
xml_document.stub_chain(:css, :attribute, :content)
|
46
|
+
parser.should_receive(:load_root_file) { parser.instance_variable_set(:@root_document, xml_document); nil }
|
47
|
+
parser.send(:metadata_path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#metadata_document' do
|
52
|
+
it 'should call load_metadata_file and assign to @metadata_document' do
|
53
|
+
parser.should_receive(:load_metadata_file) { 'loaded' }
|
54
|
+
parser.metadata_document
|
55
|
+
parser.instance_variable_get(:@metadata_document).should == 'loaded'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not call load_metadata_file if @metadata_document is not nil' do
|
59
|
+
parser.instance_variable_set(:@metadata_document, 'loaded')
|
60
|
+
parser.should_not_receive(:load_metadata_file)
|
61
|
+
parser.metadata_document
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#load_metadata_file' do
|
66
|
+
it 'should return xml document' do
|
67
|
+
parser.send(:load_root_file)
|
68
|
+
parser.send(:load_metadata_file).should be_kind_of Nokogiri::XML::Document
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should call load_epub if @zipfile is nil' do
|
72
|
+
zipfile = Zip::ZipFile.new(epub_path)
|
73
|
+
zipfile.stub(:read) { '' }
|
74
|
+
parser.should_receive(:load_epub) { parser.instance_variable_set(:@zipfile, zipfile); nil }
|
75
|
+
|
76
|
+
xml_document = Nokogiri::XML::Document.new
|
77
|
+
xml_document.stub_chain(:css, :attribute, :content)
|
78
|
+
parser.should_receive(:load_root_file) { parser.instance_variable_set(:@root_document, xml_document); nil }
|
79
|
+
|
80
|
+
parser.send(:load_metadata_file)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EPUBInfo do
|
4
|
+
let(:epub_path) { File.expand_path('spec/support/binary/metamorphosis.epub') }
|
5
|
+
|
6
|
+
describe '#get' do
|
7
|
+
it 'calls parser' do
|
8
|
+
EPUBInfo::Parser.should_receive(:parse)
|
9
|
+
EPUBInfo.get(epub_path)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
7
|
+
exit e.status_code
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'simplecov'
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter 'spec'
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'epubinfo'
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.filter_run :focus => true
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
21
|
+
end
|
22
|
+
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
|
3
|
+
<package xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="id">
|
4
|
+
<metadata>
|
5
|
+
<dc:rights>Copyrighted. Read the copyright notice inside this book for details.</dc:rights>
|
6
|
+
<dc:identifier id="id" opf:scheme="URI">http://www.gutenberg.org/ebooks/5200</dc:identifier>
|
7
|
+
<dc:contributor opf:file-as="Wyllie, David" opf:role="trl">David Wyllie</dc:contributor>
|
8
|
+
<dc:creator opf:file-as="Kafka, Franz">Franz Kafka</dc:creator>
|
9
|
+
<dc:title>Metamorphosis</dc:title>
|
10
|
+
<dc:language xsi:type="dcterms:RFC4646">en</dc:language>
|
11
|
+
<dc:subject>Psychological fiction</dc:subject>
|
12
|
+
<dc:subject>Metamorphosis -- Fiction</dc:subject>
|
13
|
+
<dc:date opf:event="publication">2005-08-17</dc:date>
|
14
|
+
<dc:date opf:event="conversion">2010-02-15T04:42:48.107119+00:00</dc:date>
|
15
|
+
<dc:source>http://www.gutenberg.org/files/5200/5200-h/5200-h.htm</dc:source>
|
16
|
+
<dc:description>Classic story of self-discovery, told in a unique manner by Kafka.</dc:description>
|
17
|
+
<dc:publisher>Random House</dc:publisher>
|
18
|
+
<meta content="item3" name="cover"/>
|
19
|
+
</metadata>
|
20
|
+
<manifest>
|
21
|
+
<item href="pgepub.css" id="item1" media-type="text/css"/>
|
22
|
+
<item href="www.gutenberg.org@files@5200@5200-h@5200-h-0.htm" id="item2" media-type="application/xhtml+xml"/>
|
23
|
+
<item href="cover.jpg" id="item3" media-type="image/jpeg"/>
|
24
|
+
<item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>
|
25
|
+
</manifest>
|
26
|
+
<spine toc="ncx">
|
27
|
+
<itemref idref="item2" linear="yes"/>
|
28
|
+
</spine>
|
29
|
+
<guide>
|
30
|
+
<reference href="cover.jpg" type="cover" title="Cover Image"/>
|
31
|
+
</guide>
|
32
|
+
</package>
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epubinfo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christof Dorner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rubyzip
|
16
|
+
requirement: &70274465012500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70274465012500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nokogiri
|
27
|
+
requirement: &70274465030960 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.5.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70274465030960
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70274465029360 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.9.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70274465029360
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: yard
|
49
|
+
requirement: &70274465028080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.5
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70274465028080
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &70274465026880 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.1.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70274465026880
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: &70274465024980 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.3
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70274465024980
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: simplecov
|
82
|
+
requirement: &70274465045040 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70274465045040
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: guard
|
93
|
+
requirement: &70274465039520 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70274465039520
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: guard-rspec
|
104
|
+
requirement: &70274465068660 !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: *70274465068660
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rb-fsevent
|
115
|
+
requirement: &70274464763340 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70274464763340
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: growl
|
126
|
+
requirement: &70274464762020 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *70274464762020
|
135
|
+
description: Currently only supports EPUB 3 specification.
|
136
|
+
email: christof@chdorner.com
|
137
|
+
executables: []
|
138
|
+
extensions: []
|
139
|
+
extra_rdoc_files:
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.rdoc
|
142
|
+
files:
|
143
|
+
- .document
|
144
|
+
- .travis.yml
|
145
|
+
- Gemfile
|
146
|
+
- Gemfile.lock
|
147
|
+
- Guardfile
|
148
|
+
- LICENSE.txt
|
149
|
+
- README.rdoc
|
150
|
+
- Rakefile
|
151
|
+
- VERSION
|
152
|
+
- lib/epubinfo.rb
|
153
|
+
- lib/epubinfo/models/book.rb
|
154
|
+
- lib/epubinfo/models/date.rb
|
155
|
+
- lib/epubinfo/models/identifier.rb
|
156
|
+
- lib/epubinfo/models/person.rb
|
157
|
+
- lib/epubinfo/parser.rb
|
158
|
+
- spec/lib/epubinfo/identifier_spec.rb
|
159
|
+
- spec/lib/epubinfo/models/book_spec.rb
|
160
|
+
- spec/lib/epubinfo/models/date_spec.rb
|
161
|
+
- spec/lib/epubinfo/models/person_spec.rb
|
162
|
+
- spec/lib/epubinfo/parser_spec.rb
|
163
|
+
- spec/lib/epubinfo_spec.rb
|
164
|
+
- spec/spec_helper.rb
|
165
|
+
- spec/support/binary/metamorphosis.epub
|
166
|
+
- spec/support/xml/metamorphosis_metadata.opf
|
167
|
+
homepage: http://github.com/chdorner/epubinfo
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
hash: -2575659408335864177
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 1.8.11
|
192
|
+
signing_key:
|
193
|
+
specification_version: 3
|
194
|
+
summary: Extracts metadata information from EPUB files
|
195
|
+
test_files: []
|