Class: Llmsherpa::Section
Overview
A section is a block of text. It can have children such as paragraphs, lists, and tables. A section has tag ‘header’.
Instance Attribute Summary collapse
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Block
#bbox, #block_idx, #block_json, #children, #left, #level, #page_idx, #parent, #sentences, #tag, #top
Instance Method Summary collapse
-
#initialize(section_json) ⇒ Section
constructor
A new instance of Section.
- #to_html(include_children = false, recurse = false) ⇒ Object
- #to_text(include_children = false, recurse = false) ⇒ Object
Methods inherited from Block
#add_child, #chunks, #iter_children, #paragraphs, #parent_chain, #parent_text, #sections, #tables, #to_context_text
Constructor Details
#initialize(section_json) ⇒ Section
Returns a new instance of Section.
152 153 154 155 |
# File 'lib/llmsherpa/blocks.rb', line 152 def initialize(section_json) super(section_json) @title = @sentences.join("\n") end |
Instance Attribute Details
#title ⇒ Object
Returns the value of attribute title.
150 151 152 |
# File 'lib/llmsherpa/blocks.rb', line 150 def title @title end |
Instance Method Details
#to_html(include_children = false, recurse = false) ⇒ Object
167 168 169 170 171 172 173 174 175 |
# File 'lib/llmsherpa/blocks.rb', line 167 def to_html(include_children = false, recurse = false) html_str = "<h#{@level + 1}>#{@title}</h#{@level + 1}>" if include_children @children.each do |child| html_str += child.to_html(include_children: recurse, recurse: recurse) end end html_str end |
#to_text(include_children = false, recurse = false) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/llmsherpa/blocks.rb', line 157 def to_text(include_children = false, recurse = false) text = @title if include_children @children.each do |child| text += "\n#{child.to_text(include_children: recurse, recurse: recurse)}" end end text end |