Class: ArticleJSON::Elements::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/article_json/elements/base.rb

Direct Known Subclasses

Embed, Heading, Image, List, Paragraph, Quote, Text, TextBox

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

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

Create an element from a hash, based on the :type field

Parameters:

  • hash (Hash)

Returns:



10
11
12
13
# 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) ⇒ Array[ArticleJSON::Elements::Base]

Create a list of elements from an array of hashes

Parameters:

  • hash_list (Array[Hash])

Returns:



18
19
20
# 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