Class: Llmsherpa::ListItem

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

Overview

A list item is a block of text. It can have child list items. A list item has tag ‘list_item’.

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

Methods inherited from Block

#add_child, #chunks, #initialize, #iter_children, #paragraphs, #parent_chain, #parent_text, #sections, #tables, #to_context_text

Constructor Details

This class inherits a constructor from Llmsherpa::Block

Instance Method Details

#to_html(include_children = false, recurse = false) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/llmsherpa/blocks.rb', line 190

def to_html(include_children = false, recurse = false)
  html_str = "<li>"
  html_str += @sentences.join("\n")
  if include_children && !@children.empty?
    html_str += "<ul>"
    @children.each do |child|
      html_str += child.to_html(include_children: recurse, recurse: recurse)
    end
    html_str += "</ul>"
  end
  html_str += "</li>"
  html_str
end

#to_text(include_children = false, recurse = false) ⇒ Object



180
181
182
183
184
185
186
187
188
# File 'lib/llmsherpa/blocks.rb', line 180

def to_text(include_children = false, recurse = false)
  text = @sentences.join("\n")
  if include_children
    @children.each do |child|
      text += "\n#{child.to_text(include_children: recurse, recurse: recurse)}"
    end
  end
  text
end