Sha256: 508009606a7663dff1e3f26965637778b263976fc7d41a6e2a297fcb7a38f40d

Contents?: true

Size: 492 Bytes

Versions: 3

Compression:

Stored size: 492 Bytes

Contents

require 'kosi'

module Slacken
  class TableElement
    attr_reader :header, :columns
    def initialize(children)
      thead, tbody = children.slice(0, 2)
      @header = thead.child # tr tag
      @columns = tbody.children # tr tags
    end

    def render
      head = header.children.map(&:to_s)
      body = columns.map { |cl| cl.children.map(&:to_s) }
      table = Kosi::Table.new(header: head).render(body)
      table.to_s.chomp
    end

    def to_s
      render
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slacken-0.1.2 lib/slacken/table_element.rb
slacken-0.1.1 lib/slacken/table_element.rb
slacken-0.1.0 lib/slacken/table_element.rb