Class: Metanorma::Collection::Config::Config
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Metanorma::Collection::Config::Config
show all
- Includes:
- Converters
- Defined in:
- lib/metanorma/collection/config/config.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#content_to_xml(model, parent, doc, type) ⇒ Object
-
#directives_from_yaml(model, value) ⇒ Object
-
#directives_to_yaml(model, doc) ⇒ Object
-
#final_from_xml(model, node) ⇒ Object
-
#final_to_xml(model, parent, doc) ⇒ Object
-
#manifest_from_xml(model, node) ⇒ Object
-
#manifest_to_xml(model, parent, doc) ⇒ Object
-
#prefatory_from_xml(model, node) ⇒ Object
-
#prefatory_to_xml(model, parent, doc) ⇒ Object
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?, #force_primary_docidentifier_xml, #force_primary_docidentifier_yaml, #nop_to_yaml
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
17
18
19
|
# File 'lib/metanorma/collection/config/config.rb', line 17
def collection
@collection
end
|
#from_xml ⇒ Object
Returns the value of attribute from_xml.
17
18
19
|
# File 'lib/metanorma/collection/config/config.rb', line 17
def from_xml
@from_xml
end
|
#path ⇒ Object
Returns the value of attribute path.
17
18
19
|
# File 'lib/metanorma/collection/config/config.rb', line 17
def path
@path
end
|
Class Method Details
.flavor_from_yaml(yaml) ⇒ Object
127
128
129
130
131
|
# File 'lib/metanorma/collection/config/config.rb', line 127
def self.flavor_from_yaml(yaml)
yaml["directives"]&.detect do |x|
x.is_a?(Hash) && x.has_key?("flavor")
end&.dig("flavor")&.upcase
end
|
.flavor_to_bibdata(file) ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/metanorma/collection/config/config.rb', line 133
def self.flavor_to_bibdata(file)
yaml = YAML.safe_load(file)
flavor = flavor_from_yaml(yaml) or return file
yaml["bibdata"] or return file
yaml["bibdata"]["ext"] ||= {}
yaml["bibdata"]["ext"]["flavor"] ||= flavor
yaml.to_yaml
end
|
.from_yaml(file) ⇒ Object
143
144
145
146
|
# File 'lib/metanorma/collection/config/config.rb', line 143
def self.from_yaml(file)
file = flavor_to_bibdata(file)
super
end
|
Instance Method Details
#content_to_xml(model, parent, doc, type) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/metanorma/collection/config/config.rb', line 93
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>"
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
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/metanorma/collection/config/config.rb', line 110
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
121
122
123
124
125
|
# File 'lib/metanorma/collection/config/config.rb', line 121
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
106
107
108
|
# File 'lib/metanorma/collection/config/config.rb', line 106
def final_from_xml(model, node)
model.final_content = node.children.map(&:to_xml).join
end
|
#final_to_xml(model, parent, doc) ⇒ Object
89
90
91
|
# File 'lib/metanorma/collection/config/config.rb', line 89
def final_to_xml(model, parent, doc)
content_to_xml(model, parent, doc, "final")
end
|
#manifest_from_xml(model, node) ⇒ Object
72
73
74
|
# File 'lib/metanorma/collection/config/config.rb', line 72
def manifest_from_xml(model, node)
model.manifest = Manifest.from_xml(node.to_xml)
end
|
#manifest_to_xml(model, parent, doc) ⇒ Object
76
77
78
79
|
# File 'lib/metanorma/collection/config/config.rb', line 76
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
81
82
83
|
# File 'lib/metanorma/collection/config/config.rb', line 81
def prefatory_from_xml(model, node)
model.prefatory_content = node.children.map(&:to_xml).join
end
|
#prefatory_to_xml(model, parent, doc) ⇒ Object
85
86
87
|
# File 'lib/metanorma/collection/config/config.rb', line 85
def prefatory_to_xml(model, parent, doc)
content_to_xml(model, parent, doc, "prefatory")
end
|