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) ⇒ TextBox

Returns a new instance of TextBox.

Parameters:



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

def initialize(content:, float: nil)
  @type = :text_box
  @content = content
  @float = float
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

Class Method Details

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

Create a text box element from Hash



27
28
29
30
31
32
# File 'lib/article_json/elements/text_box.rb', line 27

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

Instance Method Details

#to_hHash

Hash representation of this text box element

Returns:

  • (Hash)


16
17
18
19
20
21
22
# File 'lib/article_json/elements/text_box.rb', line 16

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