Class: Kitchen::BookDocument

Inherits:
Document show all
Defined in:
lib/kitchen/book_document.rb

Overview

A specialized form of Document for our books.

Instance Attribute Summary collapse

Attributes inherited from Document

#config, #id_tracker, #location

Instance Method Summary collapse

Methods inherited from Document

#clipboard, #counter, #create_element, #create_element_from_string, #encoding, #locale, #pantry, #raw, #search, #selectors, #to_html, #to_s, #to_xhtml, #to_xml

Constructor Details

#initialize(document:, short_name: :not_set, config: nil) ⇒ BookDocument

Creates a new BookDocument

Parameters:

  • document (Document, Nokogiri::XML::Document)

    the underlying document; if a Document it is converted to a Nokogiri::XML::Document

  • short_name (Symbol, String) (defaults to: :not_set)

    the book’s short name

  • config (Config) (defaults to: nil)

    the book’s configuration



20
21
22
23
24
25
# File 'lib/kitchen/book_document.rb', line 20

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

Instance Attribute Details

#short_nameSymbol (readonly)

This book’s short name, used to look up translations, etc.

Returns:

  • (Symbol)

    the name



11
12
13
# File 'lib/kitchen/book_document.rb', line 11

def short_name
  @short_name
end

Instance Method Details

#bookBookElement

Returns the top-level BookElement for this document

Returns:



31
32
33
# File 'lib/kitchen/book_document.rb', line 31

def book
  BookElement.new(node: nokogiri_document.root, document: self)
end