class ArticleJSON::Article
Attributes
Public Class Methods
Build a new article from a Google Doc HTML export @return [ArticleJSON::Article]
# File lib/article_json/article.rb, line 116 def from_google_doc_html(html) parser = ArticleJSON::Import::GoogleDoc::HTML::Parser.new(html) new(parser.parsed_content) end
Build a new article from hash (like the one generated by to_h
) @return [ArticleJSON::Article]
# File lib/article_json/article.rb, line 103 def from_hash(hash) hash = { content: hash } if hash.is_a?(Array) new(ArticleJSON::Elements::Base.parse_hash_list(hash[:content])) end
Build a new article from JSON (like the one generated by to_json
) @return [ArticleJSON::Article]
# File lib/article_json/article.rb, line 110 def from_json(json) from_hash(JSON.parse(json, symbolize_names: true)) end
@param [Array] elements
# File lib/article_json/article.rb, line 6 def initialize(elements) @article_elements = elements @additional_elements = [] end
Public Instance Methods
Exporter instance for AMP @return [ArticleJSON::Export::AMP::Exporter]
# File lib/article_json/article.rb, line 55 def amp_exporter ArticleJSON::Export::AMP::Exporter.new(elements) end
All elements of this article with optional additional elements placed in between @return [Array]
# File lib/article_json/article.rb, line 14 def elements @elements ||= begin if @additional_elements.any? ArticleJSON::Utils::AdditionalElementPlacer .new(@article_elements, @additional_elements) .merge_elements else @article_elements end end end
Exporter instance for FacebookInstantArticle @return [ArticleJSON::Export::FacebookInstantArticle::Exporter]
# File lib/article_json/article.rb, line 67 def facebook_instant_article_exporter ArticleJSON::Export::FacebookInstantArticle::Exporter.new(elements) end
Exporter instance for HTML @return [ArticleJSON::Export::HTML::Exporter]
# File lib/article_json/article.rb, line 43 def html_exporter ArticleJSON::Export::HTML::Exporter.new(elements) end
Distribute passed elements evenly throughout the article. All passed elements need to have an exporter to be represented in the rendered article. If the method is called multiple times, the order of additional elements is maintained. @param [Object] additional_elements
# File lib/article_json/article.rb, line 94 def place_additional_elements(additional_elements) # Reset the `#elements` method memoization @elements = nil @additional_elements.concat(additional_elements) end
Exporter instance for plain text @return [ArticleJSON::Export::PlainText::Exporter]
# File lib/article_json/article.rb, line 79 def plain_text_exporter ArticleJSON::Export::PlainText::Exporter.new(elements) end
AMP export of the article @return [String]
# File lib/article_json/article.rb, line 61 def to_amp amp_exporter.html end
FacebookInstantArticle export of the article @return [String]
# File lib/article_json/article.rb, line 73 def to_facebook_instant_article facebook_instant_article_exporter.html end
Hash representation of the article @return [Hash]
# File lib/article_json/article.rb, line 28 def to_h { article_json_version: VERSION, content: elements.map(&:to_h), } end
HTML export of the article @return [String]
# File lib/article_json/article.rb, line 49 def to_html html_exporter.html end
JSON representation of the article @return [String]
# File lib/article_json/article.rb, line 37 def to_json to_h.to_json end
Plain text export of the article @return [String]
# File lib/article_json/article.rb, line 85 def to_plain_text plain_text_exporter.text end