eepub 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eepub/epub.rb +27 -14
- data/lib/eepub/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47898b927d644865e6bfc5acafa1e338b105cade
|
4
|
+
data.tar.gz: 8caef5facc55165930418b10b81d476fb7b91dec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e859a6ee9cf51421654bc57e32d1894427481fab98d9d7d31a404f23312ae22321b4afdc103a195f43b620295fb450b403f8d97481ac776101feeb3231693a18
|
7
|
+
data.tar.gz: 1a8cba1bb4e01126b8c70a24b6ee1906151a2aaaea906535cdf0b9a8fb6c478d116467081990dc962b2edda91b38c2ed8b227e2ca80e67505586caf6a2cb018e
|
data/lib/eepub/epub.rb
CHANGED
@@ -2,8 +2,23 @@ require 'fileutils'
|
|
2
2
|
require 'rexml/document'
|
3
3
|
require 'zip'
|
4
4
|
|
5
|
+
using Module.new {
|
6
|
+
refine Hash do
|
7
|
+
def slice(*keys)
|
8
|
+
keys.each_with_object({}) {|k, h|
|
9
|
+
h[k] = self[k]
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
} unless {}.respond_to?(:slice)
|
14
|
+
|
5
15
|
module Eepub
|
6
16
|
class Epub
|
17
|
+
XMLNS = {
|
18
|
+
'container' => 'urn:oasis:names:tc:opendocument:xmlns:container',
|
19
|
+
'dc' => 'http://purl.org/dc/elements/1.1/',
|
20
|
+
}
|
21
|
+
|
7
22
|
def initialize(path)
|
8
23
|
@path = path
|
9
24
|
end
|
@@ -11,10 +26,10 @@ module Eepub
|
|
11
26
|
attr_reader :path
|
12
27
|
|
13
28
|
def title
|
14
|
-
@title ||= Zip::File.open(
|
15
|
-
|
29
|
+
@title ||= Zip::File.open(path) {|zip|
|
30
|
+
rootfile_doc = REXML::Document.new(rootfile_entry(zip).get_input_stream)
|
16
31
|
|
17
|
-
REXML::XPath.first(
|
32
|
+
REXML::XPath.first(rootfile_doc, '//dc:title', XMLNS.slice('dc')).text
|
18
33
|
}
|
19
34
|
end
|
20
35
|
|
@@ -24,14 +39,13 @@ module Eepub
|
|
24
39
|
FileUtils.cp path, to unless path == to
|
25
40
|
|
26
41
|
Zip::File.open to do |zip|
|
27
|
-
|
28
|
-
|
29
|
-
title_node = REXML::XPath.first(xml, '//dc:title', 'dc' => 'http://purl.org/dc/elements/1.1/')
|
42
|
+
rootfile_entry = rootfile_entry(zip)
|
43
|
+
rootfile_doc = rootfile_entry.get_input_stream(&REXML::Document.method(:new))
|
30
44
|
|
31
|
-
|
45
|
+
REXML::XPath.first(rootfile_doc, '//dc:title', XMLNS.slice('dc')).text = title
|
32
46
|
|
33
|
-
zip.get_output_stream
|
34
|
-
stream.write
|
47
|
+
zip.get_output_stream rootfile_entry.name do |stream|
|
48
|
+
stream.write rootfile_doc.to_s
|
35
49
|
end
|
36
50
|
|
37
51
|
zip.commit
|
@@ -40,12 +54,11 @@ module Eepub
|
|
40
54
|
|
41
55
|
private
|
42
56
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
path = REXML::XPath.first(container_xml, '//container:rootfile/@full-path', 'container' => 'urn:oasis:names:tc:opendocument:xmlns:container').value
|
57
|
+
def rootfile_entry(zip)
|
58
|
+
container_doc = zip.find_entry('META-INF/container.xml').get_input_stream(&REXML::Document.method(:new))
|
59
|
+
rootfile_path = REXML::XPath.first(container_doc, '//container:rootfile/@full-path', XMLNS.slice('container')).value
|
47
60
|
|
48
|
-
zip.find_entry(
|
61
|
+
zip.find_entry(rootfile_path)
|
49
62
|
end
|
50
63
|
end
|
51
64
|
end
|
data/lib/eepub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eepub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keita Urashima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|