Class: ArticleJSON::Elements::Text
- Defined in:
- lib/article_json/elements/text.rb
Instance Attribute Summary collapse
-
#bold ⇒ Object
readonly
Returns the value of attribute bold.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#italic ⇒ Object
readonly
Returns the value of attribute italic.
Attributes inherited from Base
Class Method Summary collapse
-
.parse_hash(hash) ⇒ ArticleJSON::Elements::Text
Create a text element from Hash.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Returns ‘true` if `content` is empty (see `#empty?`) or only contains whitespace (including non-breaking whitespace) characters.
-
#empty? ⇒ Boolean
Returns ‘true` if `content` has a length of zero or is `nil`.
-
#initialize(content:, bold: false, italic: false, href: nil) ⇒ Text
constructor
A new instance of Text.
-
#length ⇒ Integer
(also: #size)
Get the number of characters contained by this text element.
-
#to_h ⇒ Hash
Hash representation of this text node.
Methods inherited from Base
Constructor Details
#initialize(content:, bold: false, italic: false, href: nil) ⇒ Text
Returns a new instance of Text.
10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#bold ⇒ Object (readonly)
Returns the value of attribute bold.
4 5 6 |
# File 'lib/article_json/elements/text.rb', line 4 def bold @bold end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'lib/article_json/elements/text.rb', line 4 def content @content end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
4 5 6 |
# File 'lib/article_json/elements/text.rb', line 4 def href @href end |
#italic ⇒ Object (readonly)
Returns the value of attribute italic.
4 5 6 |
# File 'lib/article_json/elements/text.rb', line 4 def italic @italic end |
Class Method Details
.parse_hash(hash) ⇒ ArticleJSON::Elements::Text
Create a text element from Hash
54 55 56 57 58 59 60 61 |
# 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 |
Instance Method Details
#blank? ⇒ Boolean
Returns ‘true` if `content` is empty (see `#empty?`) or only contains whitespace (including non-breaking whitespace) characters
39 40 41 |
# File 'lib/article_json/elements/text.rb', line 39 def blank? empty? || content.gsub(/[\s\u00A0]/, '').empty? end |
#empty? ⇒ Boolean
Returns ‘true` if `content` has a length of zero or is `nil`
32 33 34 |
# File 'lib/article_json/elements/text.rb', line 32 def empty? !content || content.empty? end |
#length ⇒ Integer Also known as: size
Get the number of characters contained by this text element
45 46 47 48 |
# File 'lib/article_json/elements/text.rb', line 45 def length return 0 if blank? content.length end |
#to_h ⇒ Hash
Hash representation of this text node
20 21 22 23 24 25 26 27 28 |
# File 'lib/article_json/elements/text.rb', line 20 def to_h { type: type, content: content, bold: bold, italic: italic, href: href, } end |