Class: ArticleJSON::Elements::Base
- Inherits:
-
Object
- Object
- ArticleJSON::Elements::Base
- Defined in:
- lib/article_json/elements/base.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.parse_hash(hash) ⇒ ArticleJSON::Elements::Base
Create an element from a hash, based on the :type field.
-
.parse_hash_list(hash_list) ⇒ Array[ArticleJSON::Elements::Base]
Create a list of elements from an array of hashes.
Instance Attribute Details
#type ⇒ Object (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
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
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 |