Module: Kreuzberg::NodeContent

Overview

Tagged enum for node content. Each variant carries only type-specific data.

Uses ‘#[serde(tag = “node_type”)]` to avoid “type” keyword collision in Go/Java/TypeScript bindings.

Class Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'lib/kreuzberg/native.rb', line 709

def self.from_hash(hash)
  discriminator = hash[:node_type] || hash["node_type"]
  case discriminator
  when "title" then NodeContentTitle.from_hash(hash)
  when "heading" then NodeContentHeading.from_hash(hash)
  when "paragraph" then NodeContentParagraph.from_hash(hash)
  when "list" then NodeContentList.from_hash(hash)
  when "list_item" then NodeContentListItem.from_hash(hash)
  when "table" then NodeContentTable.from_hash(hash)
  when "image" then NodeContentImage.from_hash(hash)
  when "code" then NodeContentCode.from_hash(hash)
  when "quote" then NodeContentQuote.from_hash(hash)
  when "formula" then NodeContentFormula.from_hash(hash)
  when "footnote" then NodeContentFootnote.from_hash(hash)
  when "group" then NodeContentGroup.from_hash(hash)
  when "page_break" then NodeContentPageBreak.from_hash(hash)
  when "slide" then NodeContentSlide.from_hash(hash)
  when "definition_list" then NodeContentDefinitionList.from_hash(hash)
  when "definition_item" then NodeContentDefinitionItem.from_hash(hash)
  when "citation" then NodeContentCitation.from_hash(hash)
  when "admonition" then NodeContentAdmonition.from_hash(hash)
  when "raw_block" then NodeContentRawBlock.from_hash(hash)
  when "metadata_block" then NodeContentMetadataBlock.from_hash(hash)
  else raise "Unknown discriminator: #{discriminator}"
  end
end