Class: Kitchen::TableElement

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

Overview

An element for a table

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) ⇒ TableElement

Creates a new TableElement

Parameters:



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

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

Class Method Details

.short_typeSymbol

Returns the short type

Returns:

  • (Symbol)


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

def self.short_type
  :table
end

Instance Method Details

#captionElement?

Returns an element for the table caption, if present

Returns:



112
113
114
# File 'lib/kitchen/table_element.rb', line 112

def caption
  first('caption')
end

#caption_titleNokogiri::XML::NodeSet

Returns the caption title nodes

Returns:

  • (Nokogiri::XML::NodeSet)


63
64
65
# File 'lib/kitchen/table_element.rb', line 63

def caption_title
  top_caption&.first('span[data-type="title"]')&.children
end

#column_header?Boolean

Returns true if the table has a column header

Returns:

  • (Boolean)


96
97
98
# File 'lib/kitchen/table_element.rb', line 96

def column_header?
  has_class?('column-header')
end

#text_heavy?Boolean

Returns true if the table is text heavy

Returns:

  • (Boolean)


104
105
106
# File 'lib/kitchen/table_element.rb', line 104

def text_heavy?
  has_class?('text-heavy')
end

#titleNokogiri::XML::NodeSet

Returns the title nodes in the first title row element

Returns:

  • (Nokogiri::XML::NodeSet)

    Unusual to return the raw Nokogiri nodes!



38
39
40
41
# File 'lib/kitchen/table_element.rb', line 38

def title
  # TODO: replace +children+ with +element_children+?
  title_row&.first('th')&.children
end

#title_rowElement?

Returns an element for the title row, if present

Returns:



30
31
32
# File 'lib/kitchen/table_element.rb', line 30

def title_row
  top_titled? ? first('thead').first('tr') : nil
end

#top_captionElement?

Returns an element for the top caption, if present

Returns:



55
56
57
# File 'lib/kitchen/table_element.rb', line 55

def top_caption
  top_captioned? ? first('caption') : nil
end

#top_captioned?Boolean

Returns true if the table has a caption at the top that transforms to top title

Returns:

  • (Boolean)


72
73
74
# File 'lib/kitchen/table_element.rb', line 72

def top_captioned?
  has_class?('top-captioned')
end

#top_titled?Boolean

Returns true if the table has a title at the top

Returns:

  • (Boolean)


47
48
49
# File 'lib/kitchen/table_element.rb', line 47

def top_titled?
  has_class?('top-titled')
end

#unnumbered?Boolean

Returns true if the table is unnumbered

Returns:

  • (Boolean)


80
81
82
# File 'lib/kitchen/table_element.rb', line 80

def unnumbered?
  has_class?('unnumbered')
end

#unstyled?Boolean

Returns true if the table is unstyled

Returns:

  • (Boolean)


88
89
90
# File 'lib/kitchen/table_element.rb', line 88

def unstyled?
  has_class?('unstyled')
end