Class: Llmsherpa::Document
- Inherits:
-
Object
- Object
- Llmsherpa::Document
- Defined in:
- lib/llmsherpa/blocks.rb
Instance Method Summary collapse
-
#chunks ⇒ Object
Returns all the chunks in the document.
-
#initialize(blocks_json) ⇒ Document
constructor
Initializes a Document with a layout tree from the json.
-
#sections ⇒ Object
Returns all the sections in the document.
-
#tables ⇒ Object
Returns all the tables in the document.
-
#to_html ⇒ Object
Returns html for the document by iterating through all the sections.
-
#to_text ⇒ Object
Returns text of a document by iterating through all the sections ‘n’.
Constructor Details
#initialize(blocks_json) ⇒ Document
Initializes a Document with a layout tree from the json
339 340 341 342 343 |
# File 'lib/llmsherpa/blocks.rb', line 339 def initialize(blocks_json) @reader = LayoutReader.new @root_node = @reader.read(blocks_json) @json = blocks_json end |
Instance Method Details
#chunks ⇒ Object
Returns all the chunks in the document
346 347 348 |
# File 'lib/llmsherpa/blocks.rb', line 346 def chunks @root_node.chunks end |
#sections ⇒ Object
Returns all the sections in the document
356 357 358 |
# File 'lib/llmsherpa/blocks.rb', line 356 def sections @root_node.sections end |
#tables ⇒ Object
Returns all the tables in the document
351 352 353 |
# File 'lib/llmsherpa/blocks.rb', line 351 def tables @root_node.tables end |
#to_html ⇒ Object
Returns html for the document by iterating through all the sections
366 367 368 369 370 371 |
# File 'lib/llmsherpa/blocks.rb', line 366 def to_html html_str = "<html>" sections.each { |section| html_str += section.to_html(true, true) } html_str += "</html>" html_str end |
#to_text ⇒ Object
Returns text of a document by iterating through all the sections ‘n’
361 362 363 |
# File 'lib/llmsherpa/blocks.rb', line 361 def to_text sections.map { |section| section.to_text(true, true) }.join("\n") end |