Class: Metanorma::Collection::Config::Config
- Inherits:
-
Shale::Mapper
- Object
- Shale::Mapper
- Metanorma::Collection::Config::Config
show all
- Includes:
- Converters
- Defined in:
- lib/metanorma/collection/config/config.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#content_to_xml(model, parent, doc, type) ⇒ Object
-
#directive_from_xml(model, node) ⇒ Object
-
#directive_to_xml(model, parent, doc) ⇒ Object
-
#directives_from_yaml(model, value) ⇒ Object
-
#directives_to_yaml(model, doc) ⇒ Object
-
#documents_from_xml(model, value) ⇒ Object
-
#documents_to_xml(model, parent, 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, #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
|
Instance Method Details
#content_to_xml(model, parent, doc, type) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/metanorma/collection/config/config.rb', line 92
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 then 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
|
#directive_from_xml(model, node) ⇒ Object
108
109
110
111
|
# File 'lib/metanorma/collection/config/config.rb', line 108
def directive_from_xml(model, node)
model.directive ||= []
model.directive << Directive.from_xml(node.to_xml)
end
|
#directive_to_xml(model, parent, doc) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/metanorma/collection/config/config.rb', line 113
def directive_to_xml(model, parent, doc)
Array(model.directive).each do |e|
elem = e.to_xml
doc.add_element(parent, elem)
end
end
|
#directives_from_yaml(model, value) ⇒ Object
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/metanorma/collection/config/config.rb', line 120
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
131
132
133
134
135
|
# File 'lib/metanorma/collection/config/config.rb', line 131
def directives_to_yaml(model, doc)
doc["directives"] = model.directive.each_with_object([]) do |d, m|
m << { d.key => d.value }
end
end
|
#documents_from_xml(model, value) ⇒ Object
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/metanorma/collection/config/config.rb', line 137
def documents_from_xml(model, value)
x = if value.is_a?(Shale::Adapter::Nokogiri::Node)
value.content
else Nokogiri::XML(value)
end
model.documents = x.xpath(".//bibdata")
.each_with_object([]) do |b, m|
m << Bibdata.from_xml(b.to_xml)
end
end
|
#documents_to_xml(model, parent, doc) ⇒ Object
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/metanorma/collection/config/config.rb', line 148
def documents_to_xml(model, parent, doc)
b = Nokogiri::XML::Builder.new do |xml|
xml.document do |m|
model.collection.doccontainer(m) or return
end
end
b.parent.elements.first.elements.each do |x|
doc.add_element(parent, x)
end
end
|
#final_from_xml(model, node) ⇒ Object
104
105
106
|
# File 'lib/metanorma/collection/config/config.rb', line 104
def final_from_xml(model, node)
model.final_content = node.to_xml
end
|
#final_to_xml(model, parent, doc) ⇒ Object
88
89
90
|
# File 'lib/metanorma/collection/config/config.rb', line 88
def final_to_xml(model, parent, doc)
content_to_xml(model, parent, doc, "final")
end
|
#manifest_from_xml(model, node) ⇒ Object
71
72
73
|
# File 'lib/metanorma/collection/config/config.rb', line 71
def manifest_from_xml(model, node)
model.manifest = Manifest.from_xml(node.to_xml)
end
|
#manifest_to_xml(model, parent, doc) ⇒ Object
75
76
77
78
|
# File 'lib/metanorma/collection/config/config.rb', line 75
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
80
81
82
|
# File 'lib/metanorma/collection/config/config.rb', line 80
def prefatory_from_xml(model, node)
model.prefatory_content = node.to_xml
end
|
#prefatory_to_xml(model, parent, doc) ⇒ Object
84
85
86
|
# File 'lib/metanorma/collection/config/config.rb', line 84
def prefatory_to_xml(model, parent, doc)
content_to_xml(model, parent, doc, "prefatory")
end
|