Class: ArticleJSON::Elements::Embed

Inherits:
Base
  • Object
show all
Defined in:
lib/article_json/elements/embed.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(embed_type:, embed_id:, caption:, tags: []) ⇒ Embed

Returns a new instance of Embed.

Parameters:



10
11
12
13
14
15
16
# File 'lib/article_json/elements/embed.rb', line 10

def initialize(embed_type:, embed_id:, caption:, tags: [])
  @type = :embed
  @embed_type = embed_type
  @embed_id = embed_id
  @caption = caption
  @tags = tags
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



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

def caption
  @caption
end

#embed_idObject (readonly)

Returns the value of attribute embed_id.



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

def embed_id
  @embed_id
end

#embed_typeObject (readonly)

Returns the value of attribute embed_type.



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

def embed_type
  @embed_type
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Class Method Details

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

Create an embedded element from Hash



52
53
54
55
56
57
58
59
# File 'lib/article_json/elements/embed.rb', line 52

def parse_hash(hash)
  new(
    embed_type: hash[:embed_type],
    embed_id: hash[:embed_id],
    caption: parse_hash_list(hash[:caption]),
    tags: hash[:tags]
  )
end

Instance Method Details

#oembed_dataHash|nil

Obtain the oembed data for this embed element

Returns:

  • (Hash|nil)


32
33
34
# File 'lib/article_json/elements/embed.rb', line 32

def oembed_data
  oembed_resolver&.oembed_data
end

#oembed_unavailable_messageArray[ArticleJSON::Elements::Text]|nil

Returns:



37
38
39
# File 'lib/article_json/elements/embed.rb', line 37

def oembed_unavailable_message
  oembed_resolver&.unavailable_message
end

#to_hHash

Hash representation of this embedded element

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
28
# File 'lib/article_json/elements/embed.rb', line 20

def to_h
  {
    type: type,
    embed_type: embed_type,
    embed_id: embed_id,
    tags: tags,
    caption: caption.map(&:to_h),
  }
end