Class: Llmsherpa::TableRow
Overview
A table row is a block of text Base Block class assumed to be defined elsewhere
Instance Attribute Summary
Attributes inherited from Block
#bbox, #block_idx, #block_json, #children, #left, #level, #page_idx, #parent, #sentences, #tag, #top
Instance Method Summary collapse
-
#initialize(row_json) ⇒ TableRow
constructor
Initializes a TableRow with child table cells.
-
#to_html(_include_children = false, _recurse = false) ⇒ Object
Returns html for a <tr> with html from all the cells in the row as <td>.
-
#to_text(_include_children = false, _recurse = false) ⇒ Object
Returns text of a row with text from all the cells in the row delimited by ‘|’.
Methods inherited from Block
#add_child, #chunks, #iter_children, #paragraphs, #parent_chain, #parent_text, #sections, #tables, #to_context_text
Constructor Details
#initialize(row_json) ⇒ TableRow
Initializes a TableRow with child table cells
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/llmsherpa/blocks.rb', line 243 def initialize(row_json) @cells = [] if row_json["type"] == "full_row" cell = TableCell.new(row_json) @cells << cell else row_json["cells"].each do |cell_json| cell = TableCell.new(cell_json) @cells << cell end end end |
Instance Method Details
#to_html(_include_children = false, _recurse = false) ⇒ Object
Returns html for a <tr> with html from all the cells in the row as <td>
262 263 264 265 266 267 |
# File 'lib/llmsherpa/blocks.rb', line 262 def to_html(_include_children = false, _recurse = false) html_str = "<tr>" @cells.each { |cell| html_str += cell.to_html } html_str += "</tr>" html_str end |
#to_text(_include_children = false, _recurse = false) ⇒ Object
Returns text of a row with text from all the cells in the row delimited by ‘|’
257 258 259 |
# File 'lib/llmsherpa/blocks.rb', line 257 def to_text(_include_children = false, _recurse = false) @cells.map(&:to_text).join(" | ") end |