Class: Kreuzberg::Result::DocumentAnnotation

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

Overview

Annotation for a document node.

Represents inline text annotations (formatting, links) with byte-range references into the node’s text content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ DocumentAnnotation

Returns a new instance of DocumentAnnotation.



166
167
168
169
170
# File 'lib/kreuzberg/document_structure.rb', line 166

def initialize(hash)
  @start = (hash['start'] || hash[:start] || 0).to_i
  @end_offset = (hash['end'] || hash[:end] || 0).to_i
  parse_kind(hash['kind'] || hash[:kind] || {})
end

Instance Attribute Details

#annotation_typeObject (readonly)

Returns the value of attribute annotation_type.



164
165
166
# File 'lib/kreuzberg/document_structure.rb', line 164

def annotation_type
  @annotation_type
end

#end_offsetObject (readonly)

Returns the value of attribute end_offset.



164
165
166
# File 'lib/kreuzberg/document_structure.rb', line 164

def end_offset
  @end_offset
end

#startObject (readonly)

Returns the value of attribute start.



164
165
166
# File 'lib/kreuzberg/document_structure.rb', line 164

def start
  @start
end

#titleObject (readonly)

Returns the value of attribute title.



164
165
166
# File 'lib/kreuzberg/document_structure.rb', line 164

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



164
165
166
# File 'lib/kreuzberg/document_structure.rb', line 164

def url
  @url
end

Instance Method Details

#to_hHash

Convert to hash

Returns:

  • (Hash)

    Hash representation



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/kreuzberg/document_structure.rb', line 176

def to_h
  kind_hash = { annotation_type: @annotation_type }
  url = @url
  kind_hash[:url] = url if url
  title = @title
  kind_hash[:title] = title if title

  {
    start: @start,
    end: @end_offset,
    kind: kind_hash
  }
end