Class: ArticleJSON::Elements::TextBox

Inherits:
Base
  • Object
show all
Defined in:
lib/article_json/elements/text_box.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:, float: nil, tags: []) ⇒ TextBox

Returns a new instance of TextBox.

Parameters:

  • content (Array[Paragraph|Heading|List])
  • float (Symbol) (defaults to: nil)
  • tags (Array) (defaults to: [])


9
10
11
12
13
14
# File 'lib/article_json/elements/text_box.rb', line 9

def initialize(content:, float: nil, tags: [])
  @type = :text_box
  @content = content
  @float = float
  @tags = tags
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#floatObject (readonly)

Returns the value of attribute float.



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

def float
  @float
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Class Method Details

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

Create a text box element from Hash



30
31
32
33
34
35
36
# File 'lib/article_json/elements/text_box.rb', line 30

def parse_hash(hash)
  new(
    content: parse_hash_list(hash[:content]),
    float: hash[:float]&.to_sym,
    tags: hash[:tags]
  )
end

Instance Method Details

#to_hHash

Hash representation of this text box element

Returns:

  • (Hash)


18
19
20
21
22
23
24
25
# File 'lib/article_json/elements/text_box.rb', line 18

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