Class: Llmsherpa::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/llmsherpa/blocks.rb

Instance Method Summary collapse

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

#chunksObject

Returns all the chunks in the document



346
347
348
# File 'lib/llmsherpa/blocks.rb', line 346

def chunks
  @root_node.chunks
end

#sectionsObject

Returns all the sections in the document



356
357
358
# File 'lib/llmsherpa/blocks.rb', line 356

def sections
  @root_node.sections
end

#tablesObject

Returns all the tables in the document



351
352
353
# File 'lib/llmsherpa/blocks.rb', line 351

def tables
  @root_node.tables
end

#to_htmlObject

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_textObject

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