Class: Infoboxer::Tree::Table

Inherits:
Compound show all
Defined in:
lib/infoboxer/tree/table.rb

Overview

Represents table. Tables are complicated!

Instance Attribute Summary

Attributes inherited from Compound

#children

Attributes inherited from Node

#params, #parent

Instance Method Summary collapse

Methods inherited from Compound

#index_of, #initialize, #to_tree

Methods inherited from Node

#==, #children, coder, def_readers, #first?, #index, #initialize, #inspect, #next_siblings, #prev_siblings, #siblings, #text_, #to_s, #to_tree

Methods included from Navigation::Wikipath

#wikipath

Methods included from Navigation::Sections::Node

#in_sections

Methods included from Navigation::Shortcuts::Node

#bold?, #categories, #external_links, #heading?, #headings, #images, #infobox, #infoboxes, #italic?, #lists, #paragraphs, #tables, #templates, #wikilinks

Methods included from Navigation::Lookup::Node

#_lookup, #_lookup_children, #_lookup_next_siblings, #_lookup_parents, #_lookup_prev_sibling, #_lookup_prev_siblings, #_lookup_siblings, #_matches?, #lookup, #lookup_children, #lookup_next_siblings, #lookup_parents, #lookup_prev_sibling, #lookup_prev_siblings, #lookup_siblings, #matches?, #parent?

Constructor Details

This class inherits a constructor from Infoboxer::Tree::Compound

Instance Method Details

#body_rowsObject

For now, returns all table rows except #heading_row



33
34
35
36
37
38
39
# 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

#captionObject

Table caption, if exists.



20
21
22
# File 'lib/infoboxer/tree/table.rb', line 20

def caption
  children.grep(TableCaption).first
end

#empty?Boolean

Internal, used by Parser

Returns:

  • (Boolean)


10
11
12
# File 'lib/infoboxer/tree/table.rb', line 10

def empty?
  false
end

#heading_rowObject

For now, returns first table row, if it consists only of Infoboxer::Tree::TableHeadings.

FIXME: it can easily be several table heading rows



28
29
30
# File 'lib/infoboxer/tree/table.rb', line 28

def heading_row
  rows.first if rows.first&.children&.all? { |c| c.is_a?(TableHeading) }
end

#rowsObject

All table rows.



15
16
17
# File 'lib/infoboxer/tree/table.rb', line 15

def rows
  children.grep(TableRow)
end

#textObject



41
42
43
44
45
46
47
# 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