Class: Kreuzberg::Result::DjotContent::DjotImage
- Inherits:
-
Object
- Object
- Kreuzberg::Result::DjotContent::DjotImage
- Defined in:
- lib/kreuzberg/djot_content.rb
Overview
Represents an image in Djot content
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
(also: #src)
readonly
Returns the value of attribute url.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(hash_or_url = nil, alt: nil, title: nil, width: nil, height: nil, url: nil, src: nil) ⇒ DjotImage
constructor
rubocop:disable Metrics/CyclomaticComplexity.
-
#to_h ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity.
Constructor Details
#initialize(hash_or_url = nil, alt: nil, title: nil, width: nil, height: nil, url: nil, src: nil) ⇒ DjotImage
rubocop:disable Metrics/CyclomaticComplexity
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/kreuzberg/djot_content.rb', line 60 def initialize(hash_or_url = nil, alt: nil, title: nil, width: nil, height: nil, url: nil, src: nil) if hash_or_url.is_a?(Hash) # Initialize from hash (supports both 'url' and 'src' keys) @url = hash_or_url[:url] || hash_or_url['url'] || hash_or_url[:src] || hash_or_url['src'] @alt = hash_or_url[:alt] || hash_or_url['alt'] @title = hash_or_url[:title] || hash_or_url['title'] @width = hash_or_url[:width] || hash_or_url['width'] @height = hash_or_url[:height] || hash_or_url['height'] else # Initialize from keyword arguments @url = url || src || hash_or_url @alt = alt @title = title @width = width @height = height end end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt.
56 57 58 |
# File 'lib/kreuzberg/djot_content.rb', line 56 def alt @alt end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
56 57 58 |
# File 'lib/kreuzberg/djot_content.rb', line 56 def height @height end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
56 57 58 |
# File 'lib/kreuzberg/djot_content.rb', line 56 def title @title end |
#url ⇒ Object (readonly) Also known as: src
Returns the value of attribute url.
56 57 58 |
# File 'lib/kreuzberg/djot_content.rb', line 56 def url @url end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
56 57 58 |
# File 'lib/kreuzberg/djot_content.rb', line 56 def width @width end |
Instance Method Details
#to_h ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity
79 80 81 82 83 84 85 86 87 |
# File 'lib/kreuzberg/djot_content.rb', line 79 def to_h { url: @url, alt: @alt, title: @title, width: @width, height: @height }.compact end |