Class: Kreuzberg::Result::DjotContent

Inherits:
Object
  • Object
show all
Defined in:
lib/kreuzberg/djot_content.rb

Overview

Djot structured content representation

Represents document content in Djot format with structured metadata about blocks, images, links, footnotes, and other document elements.

Defined Under Namespace

Classes: DjotImage, DjotLink, Footnote, FormattedBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ DjotContent

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



141
142
143
144
145
146
147
148
149
150
# File 'lib/kreuzberg/djot_content.rb', line 141

def initialize(hash)
  @plain_text = hash['plain_text'] || hash[:plain_text] || ''
  @blocks = parse_blocks(hash['blocks'] || hash[:blocks] || [])
  @metadata_json = hash['metadata_json'] || hash[:metadata_json] || '{}'
  @tables = hash['tables'] || hash[:tables] || []
  @images = parse_images(hash['images'] || hash[:images] || [])
  @links = parse_links(hash['links'] || hash[:links] || [])
  @footnotes = parse_footnotes(hash['footnotes'] || hash[:footnotes] || [])
  @attributes = hash['attributes'] || hash[:attributes] || {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def attributes
  @attributes
end

#blocksObject (readonly)

Returns the value of attribute blocks.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def blocks
  @blocks
end

#footnotesObject (readonly)

Returns the value of attribute footnotes.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def footnotes
  @footnotes
end

#imagesObject (readonly)

Returns the value of attribute images.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def images
  @images
end

Returns the value of attribute links.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def links
  @links
end

#metadata_jsonObject (readonly)

Returns the value of attribute metadata_json.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def 
  @metadata_json
end

#plain_textObject (readonly)

Returns the value of attribute plain_text.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def plain_text
  @plain_text
end

#tablesObject (readonly)

Returns the value of attribute tables.



17
18
19
# File 'lib/kreuzberg/djot_content.rb', line 17

def tables
  @tables
end

Instance Method Details

#metadataObject

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



153
154
155
# File 'lib/kreuzberg/djot_content.rb', line 153

def 
  @metadata ||= (@metadata_json)
end

#to_hObject



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/kreuzberg/djot_content.rb', line 157

def to_h
  {
    plain_text: @plain_text,
    blocks: @blocks.map(&:to_h),
    metadata_json: @metadata_json,
    tables: @tables,
    images: @images.map(&:to_h),
    links: @links.map(&:to_h),
    footnotes: @footnotes.map(&:to_h),
    attributes: @attributes
  }
end