Sha256: 36429667a8f0c6f378c6abeb4f4f52a4949ceb07d62503eec5ae487f5d7f625f

Contents?: true

Size: 1.7 KB

Versions: 13

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Kitchen
  # An element for a table
  #
  class TableElement < ElementBase

    # Creates a new +TableElement+
    #
    # @param node [Nokogiri::XML::Node] the node this element wraps
    # @param document [Document] this element's document
    #
    def initialize(node:, document: nil)
      super(node: node,
            document: document,
            enumerator_class: TableElementEnumerator)
    end

    # Returns the short type
    # @return [Symbol]
    #
    def self.short_type
      :table
    end

    # Returns an element for the title row, if present
    #
    # @return [Element, nil]
    #
    def title_row
      top_titled? ? first('thead').first('tr') : nil
    end

    # Returns the title nodes in the first title row element
    #
    # @return [Nokogiri::XML::NodeSet] Unusual to return the raw Nokogiri nodes!
    #
    def title
      # TODO: replace +children+ with +element_children+?
      title_row&.first('th')&.children
    end

    # Returns true if the table has a title at the top
    #
    # @return [Boolean]
    #
    def top_titled?
      has_class?('top-titled')
    end

    # Returns true if the table is unnumbered
    #
    # @return [Boolean]
    #
    def unnumbered?
      has_class?('unnumbered')
    end

    # Returns true if the table is unstyled
    #
    # @return [Boolean]
    #
    def unstyled?
      has_class?('unstyled')
    end

    # Returns true if the table has a column header
    #
    # @return [Boolean]
    #
    def column_header?
      has_class?('column-header')
    end

    # Returns an element for the table caption, if present
    #
    # @return [Element, nil]
    #
    def caption
      first('caption')
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
openstax_kitchen-10.0.0 lib/kitchen/table_element.rb
openstax_kitchen-9.2.0 lib/kitchen/table_element.rb
openstax_kitchen-9.1.0 lib/kitchen/table_element.rb
openstax_kitchen-9.0.0 lib/kitchen/table_element.rb
openstax_kitchen-8.0.1 lib/kitchen/table_element.rb
openstax_kitchen-8.0.0 lib/kitchen/table_element.rb
openstax_kitchen-7.0.0 lib/kitchen/table_element.rb
openstax_kitchen-6.1.0 lib/kitchen/table_element.rb
openstax_kitchen-6.0.0 lib/kitchen/table_element.rb
openstax_kitchen-5.0.0 lib/kitchen/table_element.rb
openstax_kitchen-4.1.1 lib/kitchen/table_element.rb
openstax_kitchen-4.1.0 lib/kitchen/table_element.rb
openstax_kitchen-4.0.0 lib/kitchen/table_element.rb