class EPUB::Parser::ContentDocument
Public Class Methods
new(item)
click to toggle source
@param [EPUB::Publication::Package::Manifest::Item] item
# File lib/epub/parser/content_document.rb, line 11 def initialize(item) @item = item end
Public Instance Methods
parse()
click to toggle source
# File lib/epub/parser/content_document.rb, line 15 def parse content_document = case @item.media_type when 'application/xhtml+xml' if @item.nav? EPUB::ContentDocument::Navigation.new else EPUB::ContentDocument::XHTML.new end when 'image/svg+xml' EPUB::ContentDocument::SVG.new else nil end return content_document if content_document.nil? content_document.item = @item document = XMLDocument.new(@item.read) # parse_content_document(document) if @item.nav? content_document.navigations = parse_navigations(document) end content_document end
Private Instance Methods
find_heading(element)
click to toggle source
@param [REXML::Element, Oga::XML::Element, Nokogiri::XML::Element] element nav element @return [String] heading heading text
# File lib/epub/parser/content_document.rb, line 96 def find_heading(element) heading = element.each_element_by_xpath('./xhtml:h1|xhtml:h2|xhtml:h3|xhtml:h4|xhtml:h5|xhtml:h6|xhtml:hgroup', EPUB::NAMESPACES).first return nil if heading.nil? return heading.content unless heading.name == 'hgroup' (heading.each_element_by_xpath(".//xhtml:h1", EPUB::NAMESPACES) || heading.each_element_by_xpath(".//xhtml:h2", EPUB::NAMESPACES) || heading.each_element_by_xpath(".//xhtml:h3", EPUB::NAMESPACES) || heading.each_element_by_xpath(".//xhtml:h4", EPUB::NAMESPACES) || heading.each_element_by_xpath(".//xhtml:h5", EPUB::NAMESPACES) || heading.each_element_by_xpath(".//xhtml:h6", EPUB::NAMESPACES)).first.content end