Class: Kreuzberg::Result::DjotContent
- Inherits:
-
Object
- Object
- Kreuzberg::Result::DjotContent
- 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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#footnotes ⇒ Object
readonly
Returns the value of attribute footnotes.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#metadata_json ⇒ Object
readonly
Returns the value of attribute metadata_json.
-
#plain_text ⇒ Object
readonly
Returns the value of attribute plain_text.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
-
#initialize(hash) ⇒ DjotContent
constructor
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#metadata ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- #to_h ⇒ Object
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
17 18 19 |
# File 'lib/kreuzberg/djot_content.rb', line 17 def attributes @attributes end |
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
17 18 19 |
# File 'lib/kreuzberg/djot_content.rb', line 17 def blocks @blocks end |
#footnotes ⇒ Object (readonly)
Returns the value of attribute footnotes.
17 18 19 |
# File 'lib/kreuzberg/djot_content.rb', line 17 def footnotes @footnotes end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
17 18 19 |
# File 'lib/kreuzberg/djot_content.rb', line 17 def images @images end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
17 18 19 |
# File 'lib/kreuzberg/djot_content.rb', line 17 def links @links end |
#metadata_json ⇒ Object (readonly)
Returns the value of attribute metadata_json.
17 18 19 |
# File 'lib/kreuzberg/djot_content.rb', line 17 def @metadata_json end |
#plain_text ⇒ Object (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 |
#tables ⇒ Object (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
#metadata ⇒ Object
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_h ⇒ Object
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 |