Class: ArticleJSON::Elements::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/article_json/elements/image.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

parse_hash_list

Constructor Details

#initialize(source_url:, caption:, float: nil) ⇒ Image

Returns a new instance of Image.

Parameters:



9
10
11
12
13
14
# File 'lib/article_json/elements/image.rb', line 9

def initialize(source_url:, caption:, float: nil)
  @type = :image
  @source_url = source_url
  @caption = caption
  @float = float
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



4
5
6
# File 'lib/article_json/elements/image.rb', line 4

def caption
  @caption
end

#floatObject (readonly)

Returns the value of attribute float.



4
5
6
# File 'lib/article_json/elements/image.rb', line 4

def float
  @float
end

#source_urlObject (readonly)

Returns the value of attribute source_url.



4
5
6
# File 'lib/article_json/elements/image.rb', line 4

def source_url
  @source_url
end

Class Method Details

.parse_hash(hash) ⇒ ArticleJSON::Elements::Image

Create a image element from Hash



30
31
32
33
34
35
36
# File 'lib/article_json/elements/image.rb', line 30

def parse_hash(hash)
  new(
    source_url: hash[:source_url],
    caption: parse_hash_list(hash[:caption]),
    float: hash[:float]&.to_sym
  )
end

Instance Method Details

#to_hHash

Hash representation of this image element

Returns:

  • (Hash)


18
19
20
21
22
23
24
25
# File 'lib/article_json/elements/image.rb', line 18

def to_h
  {
    type: type,
    source_url: source_url,
    float: float,
    caption: caption.map(&:to_h),
  }
end