class Kitchen::PageElement
An element for a page
Public Class Methods
Creates a new PageElement
@param node [Nokogiri::XML::Node] the node this element wraps @param document [Document] this element's document
Kitchen::ElementBase::new
# File lib/kitchen/page_element.rb, line 13 def initialize(node:, document: nil) super(node: node, document: document, enumerator_class: PageElementEnumerator) end
Returns the short type @return [Symbol]
# File lib/kitchen/page_element.rb, line 22 def self.short_type :page end
Public Instance Methods
Returns replaces generic call to page.count_in(:chapter)
@raise [StandardError] if called on an introduction page @return [Integer]
# File lib/kitchen/page_element.rb, line 69 def count_in_chapter_without_intro_page raise 'Introduction pages cannot be counted with this method' if is_introduction? count_in(:chapter) - (ancestor(:chapter).has_introduction? ? 1 : 0) end
Returns the exercises element.
@raise [ElementNotFoundError] if no matching element is found @return [Element]
# File lib/kitchen/page_element.rb, line 113 def exercises first!('section.exercises') end
Returns the free response questions
@return [Element]
# File lib/kitchen/page_element.rb, line 121 def free_response search('section.free-response') end
Returns true if this page is an appendix
@return [Boolean]
# File lib/kitchen/page_element.rb, line 87 def is_appendix? has_class?('appendix') end
Returns true if this page is a handbook
@return [Boolean]
# File lib/kitchen/page_element.rb, line 129 def is_handbook? has_class?('handbook') end
Returns true if this page is an introduction
@return [Boolean]
# File lib/kitchen/page_element.rb, line 60 def is_introduction? @is_introduction ||= has_class?('introduction') end
Returns true if this page is a preface
@return [Boolean]
# File lib/kitchen/page_element.rb, line 79 def is_preface? has_class?('preface') end
Returns the metadata element.
@raise [ElementNotFoundError] if no matching element is found @return [Element]
# File lib/kitchen/page_element.rb, line 96 def metadata first!("div[data-type='metadata']") end
Returns the summary element.
@return [Element, nil] the summary or nil if no summary found
# File lib/kitchen/page_element.rb, line 104 def summary first(selectors.page_summary) end
Returns the title element. This method is aware that the title of the introduction page moves during the baking process.
@raise [ElementNotFoundError] if no matching element is found @return [Element]
# File lib/kitchen/page_element.rb, line 32 def title(reload: false) # The selector for intro titles changes during the baking process @title ||= begin selector = is_introduction? ? selectors.title_in_introduction_page : selectors.title_in_page first!(selector, reload: reload) end end
Returns the title's text regardless of whether the title has been baked
@return [String]
# File lib/kitchen/page_element.rb, line 44 def title_text title.children.one? ? title.text : title.first('.os-text').text end
Returns an enumerator for titles.
@return [ElementEnumerator]
# File lib/kitchen/page_element.rb, line 52 def titles search("div[data-type='document-title']") end