Class: Kitchen::ChapterElement

Inherits:
ElementBase show all
Defined in:
lib/kitchen/chapter_element.rb

Overview

An element for a chapter

Instance Attribute Summary

Attributes inherited from ElementBase

#ancestors, #document, #enumerator_class, #search_query_that_found_me, #short_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ElementBase

#[], #[]=, #add_ancestor, #add_ancestors, #add_class, #ancestor, #ancestor_elements, #append, #as_enumerator, #children, #classes, #clone, #config, #contains?, #content, #copied_id, #copy, #count_in, #cut, #data_type, descendant, descendant!, #element_children, #first, #first!, #has_ancestor?, #has_class?, #href, #href=, #id, #id=, #inner_html=, #inspect, #is?, is_the_element_class_for?, #key?, #mark_as_current_location!, #name, #name=, #pages, #pantry, #parent, #paste, #path, #preceded_by_text, #prepend, #previous, #raw, #raw_search, #remember_that_a_sub_element_was_counted, #remove_attribute, #remove_class, #replace_children, #search, #search_history, #selectors, #set, #sub_header_name, #target_label, #text, #to_html, #to_s, #to_xhtml, #to_xml, #trash, #uncount, #wrap, #wrap_children

Methods included from Mixins::BlockErrorIf

#block_error_if

Constructor Details

#initialize(node:, document: nil) ⇒ ChapterElement

Creates a new ChapterElement

Parameters:



13
14
15
16
17
# File 'lib/kitchen/chapter_element.rb', line 13

def initialize(node:, document: nil)
  super(node: node,
        document: document,
        enumerator_class: ChapterElementEnumerator)
end

Class Method Details

.short_typeSymbol

Returns the short type

Returns:

  • (Symbol)


22
23
24
# File 'lib/kitchen/chapter_element.rb', line 22

def self.short_type
  :chapter
end

Instance Method Details

#abstractsElementEnumerator

Returns an enumerator for the abstracts

Returns:



67
68
69
# File 'lib/kitchen/chapter_element.rb', line 67

def abstracts
  search('div[data-type="abstract"]')
end

#glossariesElementEnumerator

Returns an enumerator for the glossaries

Returns:



59
60
61
# File 'lib/kitchen/chapter_element.rb', line 59

def glossaries
  search("div[data-type='glossary']")
end

#has_introduction?Boolean

Returns true if the chapter has an introduction

Returns:

  • (Boolean)


51
52
53
# File 'lib/kitchen/chapter_element.rb', line 51

def has_introduction?
  @has_introduction ||= introduction_page.present?
end

#introduction_pageElement?

Returns the introduction page

Returns:



43
44
45
# File 'lib/kitchen/chapter_element.rb', line 43

def introduction_page
  pages('$.introduction').first
end

#learning_objectivesElementEnumerator

Returns an enumerator for the learning objectives

Returns:



75
76
77
# File 'lib/kitchen/chapter_element.rb', line 75

def learning_objectives
  search('section.learning-objectives')
end

#titleElement

Returns the title element (the one in the immediate children, not the one in the metadata)

Returns:

Raises:



31
32
33
34
35
36
37
# File 'lib/kitchen/chapter_element.rb', line 31

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