Class: Kreuzberg::Result::DjotContent::FormattedBlock

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

Overview

Represents a formatted block in Djot content

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_type = nil, children: nil, attributes: nil, content: nil, level: nil, block_type: nil) ⇒ FormattedBlock

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kreuzberg/djot_content.rb', line 24

def initialize(hash_or_type = nil, children: nil, attributes: nil, content: nil, level: nil, block_type: nil)
  if hash_or_type.is_a?(Hash)
    # Initialize from hash
    @block_type = hash_or_type[:block_type] || hash_or_type['block_type'] || ''
    @children = hash_or_type[:children] || hash_or_type['children']
    @attributes = hash_or_type[:attributes] || hash_or_type['attributes'] || {}
    @content = hash_or_type[:content] || hash_or_type['content']
    @level = hash_or_type[:level] || hash_or_type['level']
  else
    # Initialize from keyword arguments (for backward compatibility)
    @block_type = block_type || hash_or_type || ''
    @children = children || []
    @attributes = attributes || {}
    @content = content
    @level = level
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



21
22
23
# File 'lib/kreuzberg/djot_content.rb', line 21

def attributes
  @attributes
end

#block_typeObject (readonly)

Returns the value of attribute block_type.



21
22
23
# File 'lib/kreuzberg/djot_content.rb', line 21

def block_type
  @block_type
end

#childrenObject (readonly)

Returns the value of attribute children.



21
22
23
# File 'lib/kreuzberg/djot_content.rb', line 21

def children
  @children
end

#contentObject (readonly)

Returns the value of attribute content.



21
22
23
# File 'lib/kreuzberg/djot_content.rb', line 21

def content
  @content
end

#levelObject (readonly)

Returns the value of attribute level.



21
22
23
# File 'lib/kreuzberg/djot_content.rb', line 21

def level
  @level
end

Instance Method Details

#to_hObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



43
44
45
46
47
48
49
50
51
# File 'lib/kreuzberg/djot_content.rb', line 43

def to_h
  {
    block_type: @block_type,
    children: @children,
    attributes: @attributes,
    content: @content,
    level: @level
  }.compact
end