class ArticleJSON::Elements::Paragraph
Attributes
content[R]
Public Class Methods
new(content:)
click to toggle source
@param [Array] content
# File lib/article_json/elements/paragraph.rb, line 7 def initialize(content:) @type = :paragraph @content = content end
parse_hash(hash)
click to toggle source
Create a paragraph element from Hash @return [ArticleJSON::Elements::Paragraph]
# File lib/article_json/elements/paragraph.rb, line 48 def parse_hash(hash) new(content: parse_hash_list(hash[:content])) end
Public Instance Methods
blank?()
click to toggle source
Return `true` if the paragraph is empty or if all elements are blank @return [Boolean]
# 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?()
click to toggle source
Return `true` if the paragraph has no elements @return [Boolean]
# File lib/article_json/elements/paragraph.rb, line 23 def empty? !content || content.empty? end
length()
click to toggle source
Return the sum of all characters within the content's text elements @return [Integer]
# File lib/article_json/elements/paragraph.rb, line 37 def length return 0 if empty? @content.reduce(0) do |sum, element| sum + (element.respond_to?(:length) ? element.length : 0) end end
Also aliased as: size
to_h()
click to toggle source
Hash representation of this heading element @return [Hash]
# File lib/article_json/elements/paragraph.rb, line 14 def to_h { type: type, content: content.map(&:to_h), } end