Sha256: e2b9d067972a5aed02672781778492ccae7fbb371b94e950ff7aec63ab579bd2

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Kitchen
  # An element for a chapter
  #
  class ChapterElement < ElementBase

    # Creates a new +ChapterElement+
    #
    # @param node [Nokogiri::XML::Node] the node this element wraps
    # @param document [Document] this element's document
    #
    def initialize(node:, document: nil)
      super(node: node,
            document: document,
            enumerator_class: ChapterElementEnumerator)
    end

    # Returns the short type
    # @return [Symbol]
    #
    def self.short_type
      :chapter
    end

    # Returns the title element (the one in the immediate children, not the one in the metadata)
    #
    # @raise [ElementNotFoundError] if no matching element is found
    # @return [Element]
    #
    def title
      # Get the title in the immediate children, not the one in the metadata.  Could use
      # CSS of ":not([data-type='metadata']) >
      #       [data-type='document-title'], [data-type='document-title']"
      # but xpath is shorter
      first!("./*[@data-type = 'document-title']")
    end

    # Returns the introduction page
    #
    # @return [Element, nil]
    #
    def introduction_page
      pages('$.introduction').first
    end

    # Returns an enumerator for the glossaries
    #
    # @return [ElementEnumerator]
    #
    def glossaries
      search("div[data-type='glossary']")
    end

    # Returns an enumerator for the abstracts
    #
    # @return [ElementEnumerator]
    #
    def abstracts
      search('div[data-type="abstract"]')
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openstax_kitchen-10.0.0 lib/kitchen/chapter_element.rb
openstax_kitchen-9.2.0 lib/kitchen/chapter_element.rb
openstax_kitchen-9.1.0 lib/kitchen/chapter_element.rb
openstax_kitchen-9.0.0 lib/kitchen/chapter_element.rb