class ArticleJSON::Elements::Text

Attributes

bold[R]
content[R]
href[R]
italic[R]

Public Class Methods

new(content:, bold: false, italic: false, href: nil) click to toggle source

@param [String] content @param [Boolean] bold @param [Boolean] italic @param [String] href

# File lib/article_json/elements/text.rb, line 10
def initialize(content:, bold: false, italic: false, href: nil)
  @type = :text
  @content = content
  @bold = bold
  @italic = italic
  @href = href
end
parse_hash(hash) click to toggle source

Create a text element from Hash @return [ArticleJSON::Elements::Text]

# File lib/article_json/elements/text.rb, line 54
def parse_hash(hash)
  new(
    content: hash[:content],
    bold: hash[:bold],
    italic: hash[:italic],
    href: hash[:href]
  )
end

Public Instance Methods

blank?() click to toggle source

Returns `true` if `content` is empty (see `#empty?`) or only contains whitespace (including non-breaking whitespace) characters @return [Boolean]

# File lib/article_json/elements/text.rb, line 39
def blank?
  empty? || content.gsub(/[\s\u00A0]/, '').empty?
end
empty?() click to toggle source

Returns `true` if `content` has a length of zero or is `nil` @return [Boolean]

# File lib/article_json/elements/text.rb, line 32
def empty?
  !content || content.empty?
end
length() click to toggle source

Get the number of characters contained by this text element @return [Integer]

# File lib/article_json/elements/text.rb, line 45
def length
  return 0 if blank?
  content.length
end
Also aliased as: size
size()
Alias for: length
to_h() click to toggle source

Hash representation of this text node @return [Hash]

# File lib/article_json/elements/text.rb, line 20
def to_h
  {
    type: type,
    content: content,
    bold: bold,
    italic: italic,
    href: href,
  }
end