class Slacken::TableElement

Attributes

children[R]

Public Class Methods

new(children) click to toggle source
# File lib/slacken/table_element.rb, line 7
def initialize(children)
  @children = children
end

Public Instance Methods

render() click to toggle source
# File lib/slacken/table_element.rb, line 11
def render
  Kosi::Table.new(table_head).render(table_body).to_s.chomp
end
to_s() click to toggle source
# File lib/slacken/table_element.rb, line 15
def to_s
  render
end

Private Instance Methods

columns() click to toggle source
# File lib/slacken/table_element.rb, line 38
def columns
  if header
    tbody = children[1]
    if tbody
      tbody.children
    else
      []
    end
  else
    children
  end
end
header() click to toggle source
# File lib/slacken/table_element.rb, line 29
def header
  first_child = children.first
  if first_child.type.name == :thead
    first_child.child
  else
    nil
  end
end
table_body() click to toggle source
# File lib/slacken/table_element.rb, line 25
def table_body
  columns.map { |column| column.children.map(&:to_s) }
end
table_head() click to toggle source
# File lib/slacken/table_element.rb, line 21
def table_head
  header ? { header: header.children.map(&:to_s) } : {}
end