Class: Infoboxer::Tree::Table
- Defined in:
- lib/infoboxer/tree/table.rb
Overview
Represents table. Tables are complicated!
Instance Attribute Summary
Attributes inherited from Compound
Attributes inherited from Node
Instance Method Summary collapse
-
#body_rows ⇒ Object
For now, returns all table rows except #heading_row.
-
#caption ⇒ Object
Table caption, if exists.
-
#empty? ⇒ Boolean
Internal, used by Parser.
-
#heading_row ⇒ Object
For now, returns first table row, if it consists only of TableHeadings.
-
#rows ⇒ Object
All table rows.
- #text ⇒ Object
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
Methods included from Navigation::Sections::Node
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_rows ⇒ Object
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 |
#caption ⇒ Object
Table caption, if exists.
20 21 22 |
# File 'lib/infoboxer/tree/table.rb', line 20 def children.grep(TableCaption).first end |
#empty? ⇒ Boolean
Internal, used by Parser
10 11 12 |
# File 'lib/infoboxer/tree/table.rb', line 10 def empty? false end |
#heading_row ⇒ Object
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 |
#rows ⇒ Object
All table rows.
15 16 17 |
# File 'lib/infoboxer/tree/table.rb', line 15 def rows children.grep(TableRow) end |
#text ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/infoboxer/tree/table.rb', line 41 def text Terminal::Table.new.tap { |table| table.title = .text.sub(/\n+\Z/, '') if 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 |