Class: Metanorma::Mirror::Model::Container

Inherits:
Node
  • Object
show all
Defined in:
lib/metanorma/mirror/model/container.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#attrs, #type

Instance Method Summary collapse

Methods inherited from Node

#leaf?

Constructor Details

#initialize(type:, attrs: {}, content: []) ⇒ Container

Returns a new instance of Container.



9
10
11
12
# File 'lib/metanorma/mirror/model/container.rb', line 9

def initialize(type:, attrs: {}, content: [])
  super(type: type, attrs: attrs)
  @content = Array(content)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/metanorma/mirror/model/container.rb', line 7

def content
  @content
end

Instance Method Details

#accept_rewriter(rewriter) ⇒ Object



32
33
34
# File 'lib/metanorma/mirror/model/container.rb', line 32

def accept_rewriter(rewriter)
  rewriter.rewrite_container(self)
end

#container?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/metanorma/mirror/model/container.rb', line 14

def container?
  true
end

#text_contentObject



26
27
28
29
30
# File 'lib/metanorma/mirror/model/container.rb', line 26

def text_content
  @content.map do |item|
    item.is_a?(String) ? item : item.text_content
  end.join
end

#to_hObject



18
19
20
21
22
23
24
# File 'lib/metanorma/mirror/model/container.rb', line 18

def to_h
  h = super
  unless @content.empty?
    h["content"] = @content.map { |c| serialize_child(c) }
  end
  h
end