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

Inherits:
Node
  • Object
show all
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

Methods inherited from Node

#leaf?

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

Returns:

  • (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