class Kitchen::PageElement

An element for a page

Public Class Methods

new(node:, document: nil) click to toggle source

Creates a new PageElement

@param node [Nokogiri::XML::Node] the node this element wraps @param document [Document] this element's document

Calls superclass method 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
short_type() click to toggle source

Returns the short type @return [Symbol]

# File lib/kitchen/page_element.rb, line 22
def self.short_type
  :page
end

Public Instance Methods

count_in_chapter_without_intro_page() click to toggle source

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
exercises() click to toggle source

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
free_response() click to toggle source

Returns the free response questions

@return [Element]

# File lib/kitchen/page_element.rb, line 121
def free_response
  search('section.free-response')
end
is_appendix?() click to toggle source

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
is_handbook?() click to toggle source

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
is_introduction?() click to toggle source

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
is_preface?() click to toggle source

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
metadata() click to toggle source

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
summary() click to toggle source

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
title(reload: false) click to toggle source

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
title_text() click to toggle source

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
titles() click to toggle source

Returns an enumerator for titles.

@return [ElementEnumerator]

# File lib/kitchen/page_element.rb, line 52
def titles
  search("div[data-type='document-title']")
end