class ArticleJSON::Elements::Image

Attributes

alt[R]
caption[R]
float[R]
href[R]
source_url[R]

Public Class Methods

new(source_url:, caption:, float: nil, href: nil, alt: nil) click to toggle source

@param [String] source_url @param [Array] caption @param [Symbol] float @param [String] href @param [String] alt

# File lib/article_json/elements/image.rb, line 11
def initialize(source_url:, caption:, float: nil, href: nil, alt: nil)
  @type = :image
  @source_url = source_url
  @caption = caption
  @float = float
  @href = href
  @alt = alt
end
parse_hash(hash) click to toggle source

Create a image element from Hash @return [ArticleJSON::Elements::Image]

# File lib/article_json/elements/image.rb, line 36
def parse_hash(hash)
  new(
    source_url: hash[:source_url],
    caption: parse_hash_list(hash[:caption]),
    float: hash[:float]&.to_sym,
    href: hash[:href],
    alt: hash[:alt]
  )
end

Public Instance Methods

to_h() click to toggle source

Hash representation of this image element @return [Hash]

# File lib/article_json/elements/image.rb, line 22
def to_h
  {
    type: type,
    source_url: source_url,
    float: float,
    caption: caption.map(&:to_h),
    href: href,
    alt: alt,
  }
end