mobi 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +21 -9
- data/README.rdoc +41 -0
- data/Rakefile +3 -17
- data/VERSION +1 -1
- data/lib/mobi.rb +7 -3
- data/lib/mobi/header/exth_header.rb +46 -0
- data/lib/mobi/header/mobi_header.rb +153 -0
- data/lib/mobi/header/palm_doc_header.rb +73 -0
- data/lib/mobi/metadata.rb +45 -68
- data/lib/mobi/metadata_streams.rb +46 -0
- data/lib/mobi/stream_slicer.rb +14 -37
- data/mobi.gemspec +34 -26
- data/spec/fixtures/sherlock.mobi +0 -0
- data/spec/lib/mobi/header/exth_header_spec.rb +36 -0
- data/spec/lib/mobi/header/mobi_header_spec.rb +79 -0
- data/spec/lib/mobi/header/palm_doc_header_spec.rb +45 -0
- data/spec/lib/mobi/metadata_spec.rb +62 -0
- data/spec/lib/mobi/stream_slicer_spec.rb +64 -0
- data/spec/lib/mobi_spec.rb +10 -0
- data/spec/spec_helper.rb +4 -0
- metadata +90 -67
- data/test/helper.rb +0 -18
- data/test/test_mobi.rb +0 -7
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mobi/stream_slicer'
|
4
|
+
require 'mobi/metadata_streams'
|
5
|
+
require 'mobi/header/palm_doc_header'
|
6
|
+
|
7
|
+
describe Mobi::Header::PalmDocHeader do
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
file = File.open('spec/fixtures/sherlock.mobi')
|
11
|
+
stream = Mobi::MetadataStreams.record_zero_stream(file)
|
12
|
+
|
13
|
+
@header = Mobi::Header::PalmDocHeader.new stream
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'gets the raw compression_type' do
|
17
|
+
@header.raw_compression_type.should == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'gets the compression type' do
|
21
|
+
@header.compression_type.should == 'PalmDOC'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'gets the text length' do
|
25
|
+
@header.text_length.should == 57327
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'gets the record_count' do
|
29
|
+
@header.record_count.should == 14
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'gets the record size' do
|
33
|
+
@header.record_size.should == 4096
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'gets the raw encryption type' do
|
37
|
+
@header.raw_encryption_type.should == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'gets the encryption type' do
|
41
|
+
@header.encryption_type.should == 'None'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mobi'
|
4
|
+
|
5
|
+
describe Mobi::Metadata do
|
6
|
+
let(:file){ File.open('spec/fixtures/sherlock.mobi') }
|
7
|
+
|
8
|
+
context 'initialization' do
|
9
|
+
it 'should instantiate a StreamSlicer from the file' do
|
10
|
+
metadata = Mobi::Metadata.new(file)
|
11
|
+
|
12
|
+
metadata.data.should be_instance_of(Mobi::StreamSlicer)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should raise an exception if the book is not a mobi' do
|
16
|
+
any_instance_of(Mobi::Metadata) do |m|
|
17
|
+
mock(m).bookmobi? { false }
|
18
|
+
end
|
19
|
+
|
20
|
+
lambda{ Mobi::Metadata.new(file) }.should raise_exception(Mobi::Metadata::InvalidMobi)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'instantiating headers' do
|
24
|
+
before :all do
|
25
|
+
@metadata = Mobi::Metadata.new(file)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should instantiate a palm doc header' do
|
29
|
+
@metadata.palm_doc_header.should be_a Mobi::Header::PalmDocHeader
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should instantiate a mobi header' do
|
33
|
+
@metadata.mobi_header.should be_a Mobi::Header::MobiHeader
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should instantiate a exth_header' do
|
37
|
+
@metadata.exth_header.should be_a Mobi::Header::ExthHeader
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'instance' do
|
43
|
+
before :all do
|
44
|
+
@metadata = Mobi::Metadata.new(file)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'gets the the title of the book' do
|
48
|
+
@metadata.title.should == 'His Last Bow'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'is a bookmobi' do
|
52
|
+
@metadata.bookmobi?.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'defines delgate exth record method names to the exth record' do
|
56
|
+
mock.proxy(@metadata.exth_header).author
|
57
|
+
|
58
|
+
@metadata.author.should == 'Sir Arthur Conan Doyle'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mobi/stream_slicer'
|
4
|
+
|
5
|
+
describe Mobi::StreamSlicer do
|
6
|
+
let(:file){ File.open('spec/fixtures/sherlock.mobi') }
|
7
|
+
|
8
|
+
context "instantiation" do
|
9
|
+
it "should set the start point to 0 if no start is provided" do
|
10
|
+
ss = Mobi::StreamSlicer.new(file)
|
11
|
+
ss.start.should == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set the end point to the file end if no stop is provided" do
|
15
|
+
ss = Mobi::StreamSlicer.new(file)
|
16
|
+
ss.stop.should == 111449
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should set the start and stop points to the arguments provided" do
|
20
|
+
ss = Mobi::StreamSlicer.new(file, 1, 2)
|
21
|
+
ss.start.should == 1
|
22
|
+
ss.stop.should == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the length" do
|
26
|
+
ss = Mobi::StreamSlicer.new(file, 1, 10)
|
27
|
+
ss.length.should == 9
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set the stream to the input file" do
|
31
|
+
ss = Mobi::StreamSlicer.new(file)
|
32
|
+
ss.stream.should == file
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "#[]" do
|
37
|
+
|
38
|
+
it "should return 1 byte" do
|
39
|
+
ss = Mobi::StreamSlicer.new(file)
|
40
|
+
ss[0].length.should == 1
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should start the search from the offset provided" do
|
44
|
+
file.seek(5)
|
45
|
+
value = file.read(1)
|
46
|
+
ss = Mobi::StreamSlicer.new(file, 5)
|
47
|
+
ss[0].should == value
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return the correct number of bytes" do
|
51
|
+
file.seek(5)
|
52
|
+
value = file.read(2)
|
53
|
+
ss = Mobi::StreamSlicer.new(file, 5)
|
54
|
+
ss[0, 2].should == value
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should seek in reverse order" do
|
58
|
+
file.seek(8)
|
59
|
+
value = file.read(2)
|
60
|
+
ss = Mobi::StreamSlicer.new(file, 5)
|
61
|
+
ss[5, -2].should == value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,73 +1,91 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobi
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- jkongie
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
name: shoulda
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.11.0
|
24
22
|
type: :development
|
25
23
|
prerelease: false
|
26
|
-
version_requirements:
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.11.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rr
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
30
33
|
none: false
|
31
|
-
requirements:
|
34
|
+
requirements:
|
32
35
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 1.0.
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.4
|
35
38
|
type: :development
|
36
39
|
prerelease: false
|
37
|
-
version_requirements:
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.4
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
41
49
|
none: false
|
42
|
-
requirements:
|
50
|
+
requirements:
|
43
51
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.1.0
|
46
54
|
type: :development
|
47
55
|
prerelease: false
|
48
|
-
version_requirements:
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
52
65
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.0
|
57
70
|
type: :development
|
58
71
|
prerelease: false
|
59
|
-
version_requirements:
|
60
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.0
|
78
|
+
description: Mobi is a Rubygem that allows you to easily read MOBI e-book format metadata.
|
61
79
|
email: jkongie@gmail.com
|
62
80
|
executables: []
|
63
|
-
|
64
81
|
extensions: []
|
65
|
-
|
66
|
-
extra_rdoc_files:
|
82
|
+
extra_rdoc_files:
|
67
83
|
- LICENSE.txt
|
68
84
|
- README.rdoc
|
69
|
-
files:
|
85
|
+
files:
|
70
86
|
- .document
|
87
|
+
- .rspec
|
88
|
+
- CHANGELOG.md
|
71
89
|
- Gemfile
|
72
90
|
- Gemfile.lock
|
73
91
|
- LICENSE.txt
|
@@ -75,42 +93,47 @@ files:
|
|
75
93
|
- Rakefile
|
76
94
|
- VERSION
|
77
95
|
- lib/mobi.rb
|
96
|
+
- lib/mobi/header/exth_header.rb
|
97
|
+
- lib/mobi/header/mobi_header.rb
|
98
|
+
- lib/mobi/header/palm_doc_header.rb
|
78
99
|
- lib/mobi/metadata.rb
|
100
|
+
- lib/mobi/metadata_streams.rb
|
79
101
|
- lib/mobi/stream_slicer.rb
|
80
102
|
- mobi.gemspec
|
81
|
-
-
|
82
|
-
-
|
83
|
-
|
103
|
+
- spec/fixtures/sherlock.mobi
|
104
|
+
- spec/lib/mobi/header/exth_header_spec.rb
|
105
|
+
- spec/lib/mobi/header/mobi_header_spec.rb
|
106
|
+
- spec/lib/mobi/header/palm_doc_header_spec.rb
|
107
|
+
- spec/lib/mobi/metadata_spec.rb
|
108
|
+
- spec/lib/mobi/stream_slicer_spec.rb
|
109
|
+
- spec/lib/mobi_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
84
111
|
homepage: http://github.com/jkongie/mobi
|
85
|
-
licenses:
|
112
|
+
licenses:
|
86
113
|
- MIT
|
87
114
|
post_install_message:
|
88
115
|
rdoc_options: []
|
89
|
-
|
90
|
-
require_paths:
|
116
|
+
require_paths:
|
91
117
|
- lib
|
92
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
119
|
none: false
|
94
|
-
requirements:
|
95
|
-
- -
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
|
98
|
-
segments:
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
segments:
|
99
125
|
- 0
|
100
|
-
|
101
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
hash: -4390425668178990085
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
128
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version:
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
107
133
|
requirements: []
|
108
|
-
|
109
134
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.8.24
|
111
136
|
signing_key:
|
112
137
|
specification_version: 3
|
113
|
-
summary: A Rubygem that inspects MOBI metadata
|
114
|
-
test_files:
|
115
|
-
- test/helper.rb
|
116
|
-
- test/test_mobi.rb
|
138
|
+
summary: A Rubygem that inspects MOBI metadata.
|
139
|
+
test_files: []
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'mobi'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|