class ArticleJSON::Elements::Base

Attributes

type[R]

Public Class Methods

parse_hash(hash) click to toggle source

Create an element from a hash, based on the :type field @param [Hash] hash @return [ArticleJSON::Elements::Base]

# File lib/article_json/elements/base.rb, line 10
def parse_hash(hash)
  klass = element_classes[hash[:type].to_sym]
  klass.parse_hash(hash) unless klass.nil?
end
parse_hash_list(hash_list) click to toggle source

Create a list of elements from an array of hashes @param [Array] hash_list @return [Array]

# File lib/article_json/elements/base.rb, line 18
def parse_hash_list(hash_list)
  hash_list.map { |hash| Base.parse_hash(hash) }.compact
end

Private Class Methods

element_classes() click to toggle source
# File lib/article_json/elements/base.rb, line 24
def element_classes
  {
    embed: Embed,
    heading: Heading,
    image: Image,
    list: List,
    paragraph: Paragraph,
    quote: Quote,
    text: Text,
    text_box: TextBox,
  }
end