Class: ArticleJSON::Export::AppleNews::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/article_json/export/apple_news/exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(elements) ⇒ Exporter

Returns a new instance of Exporter.

Parameters:



6
7
8
# File 'lib/article_json/export/apple_news/exporter.rb', line 6

def initialize(elements)
  @elements = elements
end

Instance Method Details

#to_jsonString

Return the components section of an Apple News Article as JSON

Images and EmbededVideos are nested in an array with the components array when they contain captions. As Apple News skips over these nested arrays, we must flatten the array.

Returns:

  • (String)


17
18
19
# File 'lib/article_json/export/apple_news/exporter.rb', line 17

def to_json
  { components: components.flatten }.to_json
end