Class: Epub::Package
- Inherits:
-
Object
- Object
- Epub::Package
- Defined in:
- lib/epub-reader/package.rb
Instance Method Summary collapse
- #audios ⇒ Object
-
#contributor ⇒ Object
TODO: equal to creator.
- #cover ⇒ Object
-
#creator ⇒ Object
TODO: identify role TODO: identify file-as TODO: identify alternate-script TODO: identify display-seq.
- #date ⇒ Object
- #fonts ⇒ Object
- #html ⇒ Object
- #identifier ⇒ Object
- #images ⇒ Object
-
#initialize(rootfile, file) ⇒ Package
constructor
A new instance of Package.
- #javascripts ⇒ Object
- #language ⇒ Object
- #mediatype ⇒ Object
- #path ⇒ Object
- #raw ⇒ Object
-
#reading_order ⇒ Object
TODO: to parse guide [optional/deprecated] bindings [optional].
- #relative_content_path ⇒ Object
- #resources ⇒ Object
- #source ⇒ Object
- #stylesheets ⇒ Object
-
#title ⇒ Object
TODO: identify language TODO: identify subtitles.
- #toc ⇒ Object
- #type ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(rootfile, file) ⇒ Package
Returns a new instance of Package.
4 5 6 7 8 9 |
# File 'lib/epub-reader/package.rb', line 4 def initialize(rootfile, file) @rootfile = rootfile @file = file @package = get_package_content(file) @xml = Nokogiri::XML(@package).remove_namespaces! end |
Instance Method Details
#audios ⇒ Object
98 99 100 |
# File 'lib/epub-reader/package.rb', line 98 def audios resources.select{|resource| resource.attr('media-type').to_s.match(/^audio\/(mpeg|mp4)/)} end |
#contributor ⇒ Object
TODO: equal to creator
55 56 57 |
# File 'lib/epub-reader/package.rb', line 55 def contributor contributors.size > 0 ? contributors.first.text : "" end |
#cover ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/epub-reader/package.rb', line 109 def cover begin = .css('[name="cover"]') = .size == 1 ? .attr('content') : nil cover_content = || manifest.css('[properties="cover-image"]').attr('id').to_s cover_path = (cover_content.to_s.match(/\.(gif|jpe?g|png)/) ? cover_content : resources.css("##{cover_content}").attr('href').to_s) if cover_exist?(relative_content_path + cover_path) relative_content_path + cover_path elsif cover_exist?(relative_content_path + "Images/" + cover_path) relative_content_path + "Images/" + cover_path else "" end rescue "" end end |
#creator ⇒ Object
TODO: identify role TODO: identify file-as TODO: identify alternate-script TODO: identify display-seq
50 51 52 |
# File 'lib/epub-reader/package.rb', line 50 def creator creators.size > 0 ? creators.first.text : "" end |
#date ⇒ Object
59 60 61 62 |
# File 'lib/epub-reader/package.rb', line 59 def date d = .css('data') d.size > 0 ? d.text : "" end |
#fonts ⇒ Object
94 95 96 |
# File 'lib/epub-reader/package.rb', line 94 def fonts resources.select{|resource| resource.attr('media-type').to_s.match(/application\/(vnd\.ms-opentype|font-woff)/)} end |
#html ⇒ Object
82 83 84 |
# File 'lib/epub-reader/package.rb', line 82 def html resources.css('[media-type="application/xhtml+xml"]') end |
#identifier ⇒ Object
32 33 34 |
# File 'lib/epub-reader/package.rb', line 32 def identifier identifiers.css("[id=#{unique_identifier}]").text end |
#images ⇒ Object
78 79 80 |
# File 'lib/epub-reader/package.rb', line 78 def images resources.select{|resource| resource.attr('media-type').to_s.match(/^image\/(gif|jpeg|svg\+xml)/)} end |
#javascripts ⇒ Object
90 91 92 |
# File 'lib/epub-reader/package.rb', line 90 def javascripts resources.css('[media-type="text/javascript"]') end |
#language ⇒ Object
42 43 44 |
# File 'lib/epub-reader/package.rb', line 42 def language languages.first.text end |
#mediatype ⇒ Object
24 25 26 |
# File 'lib/epub-reader/package.rb', line 24 def mediatype @rootfile.attr('media-type') end |
#path ⇒ Object
15 16 17 |
# File 'lib/epub-reader/package.rb', line 15 def path @rootfile.attr('full-path').to_s end |
#raw ⇒ Object
11 12 13 |
# File 'lib/epub-reader/package.rb', line 11 def raw @package.to_s end |
#reading_order ⇒ Object
TODO: to parse guide [optional/deprecated] bindings [optional]
131 132 133 134 135 136 |
# File 'lib/epub-reader/package.rb', line 131 def reading_order spine_items.map do |item| item_id = item.attr('idref').to_s manifest.css("##{item_id}") if item_id end end |
#relative_content_path ⇒ Object
19 20 21 22 |
# File 'lib/epub-reader/package.rb', line 19 def relative_content_path i = path.rindex('/').to_i i > 0 ? path[0,i+1] : "" end |
#resources ⇒ Object
74 75 76 |
# File 'lib/epub-reader/package.rb', line 74 def resources manifest.css('item') end |
#source ⇒ Object
64 65 66 67 |
# File 'lib/epub-reader/package.rb', line 64 def source s = .css('source') s.size > 0 ? s.text : "" end |
#stylesheets ⇒ Object
86 87 88 |
# File 'lib/epub-reader/package.rb', line 86 def stylesheets resources.css('[media-type="text/css"]') end |
#title ⇒ Object
TODO: identify language TODO: identify subtitles
38 39 40 |
# File 'lib/epub-reader/package.rb', line 38 def title titles.first.text end |
#toc ⇒ Object
102 103 104 105 106 107 |
# File 'lib/epub-reader/package.rb', line 102 def toc toc_item_id = spine.attr("toc") toc_item_mimetype = "application/x-dtbncx+xml" toc_item_selector = toc_item_id ? "##{toc_item_id.to_s}" : '[media-type="#{toc_item_mimetype}"]' relative_content_path + resources.css(toc_item_selector).attr('href').to_s end |
#type ⇒ Object
69 70 71 72 |
# File 'lib/epub-reader/package.rb', line 69 def type t = .css('type') t.size > 0 ? t.text : "" end |
#version ⇒ Object
28 29 30 |
# File 'lib/epub-reader/package.rb', line 28 def version root.attr('version').to_s.to_i end |