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



31
32
33
34
35
36
37
# File 'lib/infoboxer/tree/table.rb', line 31

def body_rows
  if rows.first && rows.first.children.all? { |c| c.is_a?(TableHeading) }
    rows[1..-1]
  else
    rows
  end
end

#captionObject

Table caption, if exists.



18
19
20
# File 'lib/infoboxer/tree/table.rb', line 18

def caption
  children.grep(TableCaption).first
end

#empty?Boolean

Internal, used by Parser

Returns:

  • (Boolean)


8
9
10
# File 'lib/infoboxer/tree/table.rb', line 8

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



26
27
28
# File 'lib/infoboxer/tree/table.rb', line 26

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

#rowsObject

All table rows.



13
14
15
# File 'lib/infoboxer/tree/table.rb', line 13

def rows
  children.grep(TableRow)
end

#textObject



39
40
41
42
43
44
45
# File 'lib/infoboxer/tree/table.rb', line 39

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