Class: Metanorma::Mirror::Model::Container
- Defined in:
- lib/metanorma/mirror/model/container.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Attributes inherited from Node
Instance Method Summary collapse
- #accept_rewriter(rewriter) ⇒ Object
- #container? ⇒ Boolean
-
#initialize(type:, attrs: {}, content: []) ⇒ Container
constructor
A new instance of Container.
- #text_content ⇒ Object
- #to_h ⇒ Object
Methods inherited from Node
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
#content ⇒ Object (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
14 15 16 |
# File 'lib/metanorma/mirror/model/container.rb', line 14 def container? true end |
#text_content ⇒ Object
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_h ⇒ Object
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 |