Class: Kreuzberg::Result::DjotContent::DjotLink

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

Overview

Represents a link in Djot content

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_url = nil, text: nil, title: nil, url: nil, href: nil, link_type: nil) ⇒ DjotLink

rubocop:disable Metrics/CyclomaticComplexity



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/kreuzberg/djot_content.rb', line 96

def initialize(hash_or_url = nil, text: nil, title: nil, url: nil, href: nil, link_type: nil)
  if hash_or_url.is_a?(Hash)
    # Initialize from hash (supports both 'url' and 'href' keys)
    @url = hash_or_url[:url] || hash_or_url['url'] || hash_or_url[:href] || hash_or_url['href']
    @text = hash_or_url[:text] || hash_or_url['text']
    @title = hash_or_url[:title] || hash_or_url['title']
    @link_type = hash_or_url[:link_type] || hash_or_url['link_type']
  else
    # Initialize from keyword arguments
    @url = url || href || hash_or_url
    @text = text
    @title = title
    @link_type = link_type
  end
end

Instance Attribute Details

Returns the value of attribute link_type.



92
93
94
# File 'lib/kreuzberg/djot_content.rb', line 92

def link_type
  @link_type
end

#textObject (readonly)

Returns the value of attribute text.



92
93
94
# File 'lib/kreuzberg/djot_content.rb', line 92

def text
  @text
end

#titleObject (readonly)

Returns the value of attribute title.



92
93
94
# File 'lib/kreuzberg/djot_content.rb', line 92

def title
  @title
end

#urlObject (readonly) Also known as: href

Returns the value of attribute url.



92
93
94
# File 'lib/kreuzberg/djot_content.rb', line 92

def url
  @url
end

Instance Method Details

#to_hObject

rubocop:enable Metrics/CyclomaticComplexity



113
114
115
116
117
118
119
120
# File 'lib/kreuzberg/djot_content.rb', line 113

def to_h
  {
    url: @url,
    text: @text,
    title: @title,
    link_type: @link_type
  }.compact
end