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



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/kreuzberg/native.rb', line 340

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