Sha256: 99bb05ca2ef3502fc14dfccc45c4bb661a59c55a492e96b65f8e5250ae69957e

Contents?: true

Size: 1023 Bytes

Versions: 5

Compression:

Stored size: 1023 Bytes

Contents

# frozen_string_literal: true

module Kitchen
  # A specialized form of +Document+ for our books.
  #
  class BookDocument < Document

    # This book's short name, used to look up translations, etc.
    # @return [Symbol] the name
    #
    attr_reader :short_name

    # Creates a new BookDocument
    #
    # @param document [Document, Nokogiri::XML::Document] the underlying document;
    #   if a +Document+ it is converted to a +Nokogiri::XML::Document+
    # @param short_name [Symbol, String] the book's short name
    # @param config [Config] the book's configuration
    #
    def initialize(document:, short_name: :not_set, config: nil)
      @short_name = short_name.to_sym

      super(nokogiri_document: document.is_a?(Document) ? document.raw : document,
            config: config)
    end

    # Returns the top-level +BookElement+ for this document
    #
    # @return [BookElement]
    #
    def book
      BookElement.new(node: nokogiri_document.search('html').first, document: self)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
openstax_kitchen-4.1.0 lib/kitchen/book_document.rb
openstax_kitchen-4.0.0 lib/kitchen/book_document.rb
openstax_kitchen-3.2.0 lib/kitchen/book_document.rb
openstax_kitchen-3.1.0 lib/kitchen/book_document.rb
openstax_kitchen-3.0.0 lib/kitchen/book_document.rb