Class: ArticleJSON::Elements::Paragraph

Inherits:
Base
  • Object
show all
Defined in:
lib/article_json/elements/paragraph.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:) ⇒ Paragraph

Returns a new instance of Paragraph.

Parameters:



7
8
9
10
# File 'lib/article_json/elements/paragraph.rb', line 7

def initialize(content:)
  @type = :paragraph
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

Class Method Details

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

Create a paragraph element from Hash



38
39
40
# File 'lib/article_json/elements/paragraph.rb', line 38

def parse_hash(hash)
  new(content: parse_hash_list(hash[:content]))
end

Instance Method Details

#blank?Boolean

Return ‘true` if the paragraph is empty or if all elements are blank

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/article_json/elements/paragraph.rb', line 29

def blank?
  empty? || content.all? do |element|
    element.respond_to?(:blank?) && element.blank?
  end
end

#empty?Boolean

Return ‘true` if the paragraph has no elements

Returns:

  • (Boolean)


23
24
25
# File 'lib/article_json/elements/paragraph.rb', line 23

def empty?
  !content || content.empty?
end

#to_hHash

Hash representation of this heading element

Returns:

  • (Hash)


14
15
16
17
18
19
# File 'lib/article_json/elements/paragraph.rb', line 14

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