class ArticleJSON::Export::FacebookInstantArticle::Elements::Embed

Public Instance Methods

export() click to toggle source

Generate the embedded element node @return [Nokogiri::XML::NodeSet]

# File lib/article_json/export/facebook_instant_article/elements/embed.rb, line 10
def export
  create_element(:figure, class: 'op-interactive') do |figure|
    figure.add_child(embed_node)
    if @element.caption&.any?
      figure.add_child(caption_node(:figcaption))
    end
  end
end

Private Instance Methods

embed_node() click to toggle source

Type specific object that should be embedded @return [Nokogiri::XML::Element]

# File lib/article_json/export/facebook_instant_article/elements/embed.rb, line 23
def embed_node
  if %i(facebook_video tweet).include? @element.embed_type.to_sym
    iframe_node
  else
    embedded_object
  end
end
embedded_object() click to toggle source
# File lib/article_json/export/facebook_instant_article/elements/embed.rb, line 37
def embedded_object
  Nokogiri::HTML.fragment(@element.oembed_data[:html])
end
iframe_node() click to toggle source
# File lib/article_json/export/facebook_instant_article/elements/embed.rb, line 31
def iframe_node
  create_element(:iframe) do |div|
    div.add_child(embedded_object)
  end
end