Class: Kreuzberg::Result::DjotContent::DjotImage

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

Overview

Represents an image in Djot content

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#altObject (readonly)

Returns the value of attribute alt.



56
57
58
# File 'lib/kreuzberg/djot_content.rb', line 56

def alt
  @alt
end

#heightObject (readonly)

Returns the value of attribute height.



56
57
58
# File 'lib/kreuzberg/djot_content.rb', line 56

def height
  @height
end

#titleObject (readonly)

Returns the value of attribute title.



56
57
58
# File 'lib/kreuzberg/djot_content.rb', line 56

def title
  @title
end

#urlObject (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

#widthObject (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_hObject

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