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, #index, #initialize, #inspect, #next_siblings, #prev_siblings, #siblings, #text_, #to_s, #to_tree
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_siblings, #_lookup_siblings, #_matches?, #has_parent?, #lookup, #lookup_children, #lookup_next_siblings, #lookup_parents, #lookup_prev_siblings, #lookup_siblings, #matches?
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 |
# File 'lib/infoboxer/tree/table.rb', line 33 def body_rows rows.first && rows.first.children.all?(&call(matches?: TableHeading)) ? rows[1..-1] : rows end |
#caption ⇒ Object
Table caption, if exists.
19 20 21 |
# File 'lib/infoboxer/tree/table.rb', line 19 def children.detect(&fltr(itself: TableCaption)) end |
#empty? ⇒ Boolean
Internal, used by Parser
9 10 11 |
# File 'lib/infoboxer/tree/table.rb', line 9 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
27 28 29 30 |
# File 'lib/infoboxer/tree/table.rb', line 27 def heading_row rows.first && rows.first.children.all?(&call(matches?: TableHeading)) ? rows.first : nil end |
#rows ⇒ Object
All table rows.
14 15 16 |
# File 'lib/infoboxer/tree/table.rb', line 14 def rows children.select(&fltr(itself: TableRow)) end |
#text ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/infoboxer/tree/table.rb', line 39 def text table = Terminal::Table.new if table.title = .text.sub(/\n+\Z/, '') end if heading_row table.headings = heading_row.children.map(&:text). map(&call(sub: [/\n+\Z/, ''])) end table.rows = body_rows.map{|r| r.children.map(&:text). map(&call(sub: [/\n+\Z/, ''])) } table.to_s + "\n\n" end |