Class: ArticleJSON::Elements::Heading

Inherits:
Base
  • Object
show all
Defined in:
lib/article_json/elements/heading.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(level:, content:) ⇒ Heading

Returns a new instance of Heading.

Parameters:

  • level (String)
  • content (String)


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

def initialize(level:, content:)
  @level = level
  @content = content
  @type = :heading
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

Class Method Details

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

Create a heading element from Hash



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

def parse_hash(hash)
  new(
    level: hash[:level].to_i,
    content: hash[:content]
  )
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/heading.rb', line 16

def to_h
  {
    type: type,
    level: level,
    content: content,
  }
end