Class: EPUB::ContentDocument::XHTML

Inherits:
Object
  • Object
show all
Defined in:
lib/epub/content_document/xhtml.rb

Direct Known Subclasses

Navigation

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#itemObject

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

#nokogiriNokogiri::XML::Document

Returns content as Nokogiri::XML::Document object

Returns:

  • (Nokogiri::XML::Document)

    content as Nokogiri::XML::Document object



36
37
38
39
# File 'lib/epub/content_document/xhtml.rb', line 36

def nokogiri
  require 'nokogiri'
  @nokogiri ||= Nokogiri.XML(raw_document)
end

#read(detect_encoding: true) ⇒ String Also known as: raw_document

Returns the content string.

Parameters:

Returns:

  • (String)

    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

#rexmlREXML::Document

Returns content as REXML::Document object

Returns:

  • (REXML::Document)

    content as REXML::Document object



31
32
33
# File 'lib/epub/content_document/xhtml.rb', line 31

def rexml
  @rexml ||= REXML::Document.new(raw_document)
end

#titleString

Returns the value of title element. If none, returns empty string

Returns:

  • (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 = rexml.get_elements('.//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.

Returns:

  • (true|false)

    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