Sha256: 29477bc10e2e93d477058458932110f70a105bcccc403cd11dcd5786aa968a2b

Contents?: true

Size: 1022 Bytes

Versions: 17

Compression:

Stored size: 1022 Bytes

Contents

module EPUB
  module ContentDocument
    class XHTML
      attr_accessor :item

      # @return [String] Returns the content string.
      def read
        item.read
      end
      alias raw_document read

      # @return [true|false] Whether referenced directly from spine or not.
      def top_level?
        !! item.itemref
      end

      # @return [String] Returns the value of title element.
      #                  If none, returns empty string
      def title
        title_elem = nokogiri.search('title').first
        if title_elem
          title_elem.text
        else
          warn 'title element not found'
          ''
        end
      end

      # @return [REXML::Document] content as REXML::Document object
      def rexml
        require 'rexml/document'
        @rexml ||= REXML::Document.new(raw_document)
      end

      # @return [Nokogiri::XML::Document] content as Nokogiri::XML::Document object
      def nokogiri
        @nokogiri ||= Nokogiri.XML(raw_document)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
epub-parser-0.3.2 lib/epub/content_document/xhtml.rb
epub-parser-0.3.1 lib/epub/content_document/xhtml.rb
epub-parser-0.3.0 lib/epub/content_document/xhtml.rb
epub-parser-0.2.9 lib/epub/content_document/xhtml.rb
epub-parser-0.2.8 lib/epub/content_document/xhtml.rb
epub-parser-0.2.7 lib/epub/content_document/xhtml.rb
epub-parser-0.2.6 lib/epub/content_document/xhtml.rb
epub-parser-0.2.5 lib/epub/content_document/xhtml.rb
epub-parser-0.2.4 lib/epub/content_document/xhtml.rb
epub-parser-0.2.3 lib/epub/content_document/xhtml.rb
epub-parser-0.1.8 lib/epub/content_document/xhtml.rb
epub-parser-0.1.7.1 lib/epub/content_document/xhtml.rb
epub-parser-0.1.7 lib/epub/content_document/xhtml.rb
epub-parser-io-0.1.6b lib/epub/content_document/xhtml.rb
epub-parser-io-0.1.6a lib/epub/content_document/xhtml.rb
epub-parser-io-0.1.6 lib/epub/content_document/xhtml.rb
epub-parser-0.1.6 lib/epub/content_document/xhtml.rb