Module: Kreuzberg::FormatMetadata

Overview

Format-specific metadata (discriminated union).

Only one format type can exist per extraction result. This provides type-safe, clean metadata without nested optionals.

Class Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
# File 'lib/kreuzberg/native.rb', line 2368

def self.from_hash(hash)
  discriminator = hash[:format_type] || hash["format_type"]
  case discriminator
  when "pdf" then FormatMetadataPdf.from_hash(hash)
  when "docx" then FormatMetadataDocx.from_hash(hash)
  when "excel" then FormatMetadataExcel.from_hash(hash)
  when "email" then FormatMetadataEmail.from_hash(hash)
  when "pptx" then FormatMetadataPptx.from_hash(hash)
  when "archive" then FormatMetadataArchive.from_hash(hash)
  when "image" then FormatMetadataImage.from_hash(hash)
  when "xml" then FormatMetadataXml.from_hash(hash)
  when "text" then FormatMetadataText.from_hash(hash)
  when "html" then FormatMetadataHtml.from_hash(hash)
  when "ocr" then FormatMetadataOcr.from_hash(hash)
  when "csv" then FormatMetadataCsv.from_hash(hash)
  when "bibtex" then FormatMetadataBibtex.from_hash(hash)
  when "citation" then FormatMetadataCitation.from_hash(hash)
  when "fiction_book" then FormatMetadataFictionBook.from_hash(hash)
  when "dbf" then FormatMetadataDbf.from_hash(hash)
  when "jats" then FormatMetadataJats.from_hash(hash)
  when "epub" then FormatMetadataEpub.from_hash(hash)
  when "pst" then FormatMetadataPst.from_hash(hash)
  when "audio" then FormatMetadataAudio.from_hash(hash)
  when "code" then FormatMetadataCode.from_hash(hash)
  else raise "Unknown discriminator: #{discriminator}"
  end
end