Class: ArticleJSON::Elements::List

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

Instance Attribute Summary collapse

Attributes inherited from Base

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

parse_hash_list

Constructor Details

#initialize(content:, list_type: :unordered) ⇒ List

Returns a new instance of List.

Parameters:



8
9
10
11
12
# File 'lib/article_json/elements/list.rb', line 8

def initialize(content:, list_type: :unordered)
  @type = :list
  @content = content
  @list_type = list_type
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#list_typeObject (readonly)

Returns the value of attribute list_type.



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

def list_type
  @list_type
end

Class Method Details

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

Create a list element from Hash



27
28
29
30
31
32
# File 'lib/article_json/elements/list.rb', line 27

def parse_hash(hash)
  new(
    content: parse_hash_list(hash[:content]),
    list_type: hash[:list_type].to_sym
  )
end

Instance Method Details

#to_hHash

Hash representation of this heading element

Returns:

  • (Hash)


16
17
18
19
20
21
22
# File 'lib/article_json/elements/list.rb', line 16

def to_h
  {
    type: type,
    list_type: list_type,
    content: content.map(&:to_h),
  }
end