Class: EPUB::ContentDocument::XHTML
- Inherits:
-
Object
- Object
- EPUB::ContentDocument::XHTML
- Defined in:
- lib/epub/content_document/xhtml.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#item ⇒ Object
Returns the value of attribute item.
Instance Method Summary collapse
-
#nokogiri ⇒ Nokogiri::XML::Document
Content as Nokogiri::XML::Document object.
-
#read(detect_encoding: true) ⇒ String
(also: #raw_document)
Returns the content string.
-
#rexml ⇒ REXML::Document
Content as REXML::Document object.
-
#title ⇒ String
Returns the value of title element.
-
#top_level? ⇒ true|false
Whether referenced directly from spine or not.
Instance Attribute Details
#item ⇒ Object
Returns the value of attribute item.
4 5 6 |
# File 'lib/epub/content_document/xhtml.rb', line 4 def item @item end |
Instance Method Details
#nokogiri ⇒ Nokogiri::XML::Document
Returns content as Nokogiri::XML::Document object.
37 38 39 |
# File 'lib/epub/content_document/xhtml.rb', line 37 def nokogiri @nokogiri ||= Nokogiri.XML(raw_document) end |
#read(detect_encoding: true) ⇒ String Also known as: raw_document
Returns the content string.
8 9 10 |
# File 'lib/epub/content_document/xhtml.rb', line 8 def read(detect_encoding: true) item.read(detect_encoding: detect_encoding) end |
#rexml ⇒ REXML::Document
Returns content as REXML::Document object.
31 32 33 34 |
# File 'lib/epub/content_document/xhtml.rb', line 31 def rexml require 'rexml/document' @rexml ||= REXML::Document.new(raw_document) end |
#title ⇒ String
Returns the value of title element. If none, returns empty string
20 21 22 23 24 25 26 27 28 |
# File 'lib/epub/content_document/xhtml.rb', line 20 def title title_elem = nokogiri.search('title').first if title_elem title_elem.text else warn 'title element not found' '' end end |
#top_level? ⇒ true|false
Returns Whether referenced directly from spine or not.
14 15 16 |
# File 'lib/epub/content_document/xhtml.rb', line 14 def top_level? !! item.itemref end |