Class: ArticleJSON::Elements::Heading
- Defined in:
- lib/article_json/elements/heading.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Attributes inherited from Base
Class Method Summary collapse
-
.parse_hash(hash) ⇒ ArticleJSON::Elements::Heading
Create a heading element from Hash.
Instance Method Summary collapse
-
#initialize(level:, content:) ⇒ Heading
constructor
A new instance of Heading.
-
#to_h ⇒ Hash
Hash representation of this heading element.
Methods inherited from Base
Constructor Details
#initialize(level:, content:) ⇒ Heading
Returns a new instance of Heading.
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
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'lib/article_json/elements/heading.rb', line 4 def content @content end |
#level ⇒ Object (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_h ⇒ Hash
Hash representation of this heading element
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 |