Class: Metanorma::Collection::Config::Config

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Includes:
Converters
Defined in:
lib/metanorma/collection/config/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Converters

#bibdata_from_xml, #bibdata_from_yaml, #bibdata_to_xml, #bibdata_to_yaml, #documents_from_xml, #documents_to_xml, #documents_to_xml?, #nop_to_yaml

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



18
19
20
# File 'lib/metanorma/collection/config/config.rb', line 18

def collection
  @collection
end

#from_xmlObject

Returns the value of attribute from_xml.



18
19
20
# File 'lib/metanorma/collection/config/config.rb', line 18

def from_xml
  @from_xml
end

#pathObject

Returns the value of attribute path.



18
19
20
# File 'lib/metanorma/collection/config/config.rb', line 18

def path
  @path
end

Instance Method Details

#content_to_xml(model, parent, doc, type) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/metanorma/collection/config/config.rb', line 94

def content_to_xml(model, parent, doc, type)
  x = model.send("#{type}_content") or return
  n = Nokogiri::XML(x)
  elem = if n.elements.size == 1
           "<#{type}-content>#{x}</#{type}-content>" # n.root
         else
           b = Nokogiri::XML::Builder.new
           model.collection.content_to_xml(type, b)
           b.parent.elements.first
         end
  doc.add_element(parent, elem)
end

#directives_from_yaml(model, value) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/metanorma/collection/config/config.rb', line 111

def directives_from_yaml(model, value)
  model.directive = value&.each_with_object([]) do |v, m|
    m << case v
         when String then Directive.new(key: v)
         when Hash
           k = v.keys.first
           Directive.new(key: k, value: v[k])
         end
  end
end

#directives_to_yaml(model, doc) ⇒ Object



122
123
124
125
126
# File 'lib/metanorma/collection/config/config.rb', line 122

def directives_to_yaml(model, doc)
  doc["directives"] = model.directive.each_with_object([]) do |d, m|
    m << { d.key => d.value }
  end
end

#final_from_xml(model, node) ⇒ Object



107
108
109
# File 'lib/metanorma/collection/config/config.rb', line 107

def final_from_xml(model, node)
  model.final_content = node
end

#final_to_xml(model, parent, doc) ⇒ Object



90
91
92
# File 'lib/metanorma/collection/config/config.rb', line 90

def final_to_xml(model, parent, doc)
  content_to_xml(model, parent, doc, "final")
end

#manifest_from_xml(model, node) ⇒ Object



73
74
75
# File 'lib/metanorma/collection/config/config.rb', line 73

def manifest_from_xml(model, node)
  model.manifest = Manifest.from_xml(node.node.to_xml)
end

#manifest_to_xml(model, parent, doc) ⇒ Object



77
78
79
80
# File 'lib/metanorma/collection/config/config.rb', line 77

def manifest_to_xml(model, parent, doc)
  model.collection&.manifest&.clean_manifest(model.manifest)
  doc.add_element(parent, model.manifest.to_xml)
end

#prefatory_from_xml(model, node) ⇒ Object



82
83
84
# File 'lib/metanorma/collection/config/config.rb', line 82

def prefatory_from_xml(model, node)
  model.prefatory_content = node
end

#prefatory_to_xml(model, parent, doc) ⇒ Object



86
87
88
# File 'lib/metanorma/collection/config/config.rb', line 86

def prefatory_to_xml(model, parent, doc)
  content_to_xml(model, parent, doc, "prefatory")
end