class Infoboxer::Tree::Table

Represents table. Tables are complicated!

Public Instance Methods

body_rows() click to toggle source

For now, returns all table rows except {#heading_row}

# File lib/infoboxer/tree/table.rb, line 33
def body_rows
  if rows.first&.children&.all? { |c| c.is_a?(TableHeading) }
    rows[1..]
  else
    rows
  end
end
caption() click to toggle source

Table caption, if exists.

# File lib/infoboxer/tree/table.rb, line 20
def caption
  children.grep(TableCaption).first
end
empty?() click to toggle source

Internal, used by {Parser}

# File lib/infoboxer/tree/table.rb, line 10
def empty?
  false
end
heading_row() click to toggle source

For now, returns first table row, if it consists only of {TableHeading}s.

FIXME: it can easily be several table heading rows

# File lib/infoboxer/tree/table.rb, line 28
def heading_row
  rows.first if rows.first&.children&.all? { |c| c.is_a?(TableHeading) }
end
rows() click to toggle source

All table rows.

# File lib/infoboxer/tree/table.rb, line 15
def rows
  children.grep(TableRow)
end
text() click to toggle source
# File lib/infoboxer/tree/table.rb, line 41
def text
  Terminal::Table.new.tap { |table|
    table.title = caption.text.sub(/\n+\Z/, '') if caption
    table.headings = heading_row.children.map(&:text_) if heading_row
    table.rows = body_rows.map { |r| r.children.map(&:text_) }
  }.to_s + "\n\n"
end