Class: Kreuzberg::Result::DjotContent::DjotLink
- Inherits:
-
Object
- Object
- Kreuzberg::Result::DjotContent::DjotLink
- Defined in:
- lib/kreuzberg/djot_content.rb
Overview
Represents a link in Djot content
Instance Attribute Summary collapse
-
#link_type ⇒ Object
readonly
Returns the value of attribute link_type.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
(also: #href)
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(hash_or_url = nil, text: nil, title: nil, url: nil, href: nil, link_type: nil) ⇒ DjotLink
constructor
rubocop:disable Metrics/CyclomaticComplexity.
-
#to_h ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
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
#link_type ⇒ Object (readonly)
Returns the value of attribute link_type.
92 93 94 |
# File 'lib/kreuzberg/djot_content.rb', line 92 def link_type @link_type end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
92 93 94 |
# File 'lib/kreuzberg/djot_content.rb', line 92 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
92 93 94 |
# File 'lib/kreuzberg/djot_content.rb', line 92 def title @title end |
#url ⇒ Object (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_h ⇒ Object
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 |