Class: Metanorma::Mirror::Model::Container
- Defined in:
- lib/metanorma/mirror/model/container.rb,
lib/metanorma/mirror/model/container.rb
Overview
content is declared after the sibling node classes exist: the union member list references Container itself, and lutaml-model resolves union members eagerly at declaration time. Deserialized children dispatch through Factory (the child's shape — content array vs leaf vs text — picks the class), which is why the union never receives raw hashes on the way in.
Instance Method Summary collapse
- #accept_rewriter(rewriter) ⇒ Object
- #container? ⇒ Boolean
- #content_from_mapping(model, value) ⇒ Object
-
#initialize(type: nil, attrs: {}, content: []) ⇒ Container
constructor
A new instance of Container.
- #text_content ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(type: nil, attrs: {}, content: []) ⇒ Container
Returns a new instance of Container.
7 8 9 10 |
# File 'lib/metanorma/mirror/model/container.rb', line 7 def initialize(type: nil, attrs: {}, content: [], **) super(type: type, attrs: attrs, **) self.content = Array(content) end |
Instance Method Details
#accept_rewriter(rewriter) ⇒ Object
22 23 24 |
# File 'lib/metanorma/mirror/model/container.rb', line 22 def accept_rewriter(rewriter) rewriter.rewrite_container(self) end |
#container? ⇒ Boolean
12 13 14 |
# File 'lib/metanorma/mirror/model/container.rb', line 12 def container? true end |
#content_from_mapping(model, value) ⇒ Object
42 43 44 45 46 |
# File 'lib/metanorma/mirror/model/container.rb', line 42 def content_from_mapping(model, value) model.content = Array(value).map do |child| child.is_a?(Hash) ? Factory.from_hash(child) : child end end |
#text_content ⇒ Object
16 17 18 19 20 |
# File 'lib/metanorma/mirror/model/container.rb', line 16 def text_content content.map do |item| item.is_a?(String) ? item : item.text_content end.join end |