eepub 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c45185b9bc841d1dffbbeadf217e5f78c88e480e
4
- data.tar.gz: '092f0704c9c51d76fe5b3284142bf13cbc4d9b86'
3
+ metadata.gz: 52fbfd183089157649fb9784374b79ebbae527ba
4
+ data.tar.gz: 75ab452c76d5dab0473feeb9c80be18be909f4a4
5
5
  SHA512:
6
- metadata.gz: afb59c1326599703a5acd010533975bc1bdcd1c475c8e20577376968dfb72378dc43a6234997417a69f155382ca13968ef27a83230a3f3fe22fd4e3b4bf92d25
7
- data.tar.gz: 8185b4abbfb85da2be4f9f9372746e5e067215d38bca441606c9d34c955a660c12d2126f284881d6112b02ad111be229cc9382823f130c7c781d149d81b19809
6
+ metadata.gz: 68fd2bad5e3febe6070d6966548447bde98bcba3023de7b619dab789bd26409127f09053fcb8dd96d598d719a2b83f031481905a6d7be9bbc270c9cf935724f3
7
+ data.tar.gz: e20e6a42c7b2d2f22b780a8fe7c07d9050b04bebf77f8bb7369ffffecab43b2510056716aec897efd8d770528def6b23b63f2a0ad26fe9b8709582c783d263f1
@@ -27,9 +27,9 @@ module Eepub
27
27
 
28
28
  def title
29
29
  @title ||= Zip::File.open(path) {|zip|
30
- rootfile_doc = rootfile_entry(zip).get_input_stream(&REXML::Document.method(:new))
30
+ rootfile_doc = parse_xml(find_rootfile_entry(zip))
31
31
 
32
- REXML::XPath.first(rootfile_doc, '//dc:title', XMLNS.slice('dc')).text
32
+ get_title_element(rootfile_doc).text
33
33
  }
34
34
  end
35
35
 
@@ -39,10 +39,10 @@ module Eepub
39
39
  FileUtils.cp path, to unless path == to
40
40
 
41
41
  Zip::File.open to do |zip|
42
- rootfile_entry = rootfile_entry(zip)
43
- rootfile_doc = rootfile_entry.get_input_stream(&REXML::Document.method(:new))
42
+ rootfile_entry = find_rootfile_entry(zip)
43
+ rootfile_doc = parse_xml(rootfile_entry)
44
44
 
45
- REXML::XPath.first(rootfile_doc, '//dc:title', XMLNS.slice('dc')).text = title
45
+ get_title_element(rootfile_doc).text = title
46
46
 
47
47
  zip.get_output_stream rootfile_entry.name, &rootfile_doc.method(:write)
48
48
  zip.commit
@@ -51,11 +51,20 @@ module Eepub
51
51
 
52
52
  private
53
53
 
54
- def rootfile_entry(zip)
55
- container_doc = zip.find_entry('META-INF/container.xml').get_input_stream(&REXML::Document.method(:new))
54
+ def find_rootfile_entry(zip)
55
+ container_doc = parse_xml(zip.find_entry('META-INF/container.xml'))
56
56
  rootfile_path = REXML::XPath.first(container_doc, '//container:rootfile/@full-path', XMLNS.slice('container')).value
57
57
 
58
58
  zip.find_entry(rootfile_path)
59
59
  end
60
+
61
+ def parse_xml(entry)
62
+ content = entry.get_input_stream.read
63
+ REXML::Document.new(content)
64
+ end
65
+
66
+ def get_title_element(doc)
67
+ REXML::XPath.first(doc, '//dc:title', XMLNS.slice('dc'))
68
+ end
60
69
  end
61
70
  end
@@ -1,3 +1,3 @@
1
1
  module Eepub
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
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.3
4
+ version: 0.3.4
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-22 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip