sts 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +1 -1
- data/.rubocop.yml +12 -0
- data/Gemfile +6 -0
- data/lib/sts/mapper.rb +442 -0
- data/lib/sts/niso_sts/app.rb +49 -0
- data/lib/sts/niso_sts/app_group.rb +19 -0
- data/lib/sts/niso_sts/back.rb +12 -2
- data/lib/sts/niso_sts/body.rb +2 -2
- data/lib/sts/niso_sts/caption.rb +47 -0
- data/lib/sts/niso_sts/custom_meta.rb +23 -0
- data/lib/sts/niso_sts/custom_meta_group.rb +18 -0
- data/lib/sts/niso_sts/def.rb +19 -0
- data/lib/sts/niso_sts/def_item.rb +24 -0
- data/lib/sts/niso_sts/def_list.rb +28 -0
- data/lib/sts/niso_sts/display_formula.rb +27 -0
- data/lib/sts/niso_sts/document_identification.rb +7 -7
- data/lib/sts/niso_sts/ext_link.rb +20 -0
- data/lib/sts/niso_sts/figure.rb +40 -0
- data/lib/sts/niso_sts/fn.rb +24 -0
- data/lib/sts/niso_sts/fn_group.rb +19 -0
- data/lib/sts/niso_sts/front.rb +9 -2
- data/lib/sts/niso_sts/graphic.rb +29 -0
- data/lib/sts/niso_sts/inline_formula.rb +22 -0
- data/lib/sts/niso_sts/list.rb +9 -1
- data/lib/sts/niso_sts/list_item.rb +25 -0
- data/lib/sts/niso_sts/meta_note.rb +24 -0
- data/lib/sts/niso_sts/metadata_iso.rb +2 -2
- data/lib/sts/niso_sts/metadata_std.rb +59 -0
- data/lib/sts/niso_sts/mixed_citation.rb +27 -0
- data/lib/sts/niso_sts/non_normative_example.rb +22 -0
- data/lib/sts/niso_sts/non_normative_note.rb +4 -2
- data/lib/sts/niso_sts/object_id.rb +23 -0
- data/lib/sts/niso_sts/page_count.rb +2 -2
- data/lib/sts/niso_sts/paragraph.rb +36 -2
- data/lib/sts/niso_sts/permissions.rb +20 -0
- data/lib/sts/niso_sts/reference.rb +4 -1
- data/lib/sts/niso_sts/reference_list.rb +6 -1
- data/lib/sts/niso_sts/reference_standard.rb +17 -6
- data/lib/sts/niso_sts/section.rb +43 -9
- data/lib/sts/niso_sts/standard.rb +14 -1
- data/lib/sts/niso_sts/standard_identification.rb +13 -7
- data/lib/sts/niso_sts/standard_ref.rb +2 -2
- data/lib/sts/niso_sts/std_cross_reference.rb +18 -0
- data/lib/sts/niso_sts/std_id.rb +24 -0
- data/lib/sts/niso_sts/std_id_group.rb +19 -0
- data/lib/sts/niso_sts/term_display.rb +2 -2
- data/lib/sts/niso_sts/term_section.rb +10 -3
- data/lib/sts/niso_sts/title.rb +22 -0
- data/lib/sts/niso_sts/title_wrap.rb +6 -2
- data/lib/sts/niso_sts.rb +1 -0
- data/lib/sts/tbx_iso_tml/bold.rb +18 -0
- data/lib/sts/tbx_iso_tml/caption.rb +17 -0
- data/lib/sts/tbx_iso_tml/col.rb +23 -0
- data/lib/sts/tbx_iso_tml/definition.rb +24 -1
- data/lib/sts/tbx_iso_tml/entailed_term.rb +26 -0
- data/lib/sts/tbx_iso_tml/example.rb +16 -1
- data/lib/sts/tbx_iso_tml/external_graphic.rb +2 -2
- data/lib/sts/tbx_iso_tml/external_source.rb +2 -2
- data/lib/sts/tbx_iso_tml/fn.rb +23 -0
- data/lib/sts/tbx_iso_tml/fn_group.rb +19 -0
- data/lib/sts/tbx_iso_tml/geographical_usage.rb +2 -2
- data/lib/sts/tbx_iso_tml/grammatical_gender.rb +2 -2
- data/lib/sts/tbx_iso_tml/grammatical_number.rb +2 -2
- data/lib/sts/tbx_iso_tml/italic.rb +20 -0
- data/lib/sts/tbx_iso_tml/lang_set.rb +11 -7
- data/lib/sts/tbx_iso_tml/math.rb +62 -0
- data/lib/sts/tbx_iso_tml/mfenced.rb +43 -0
- data/lib/sts/tbx_iso_tml/mfrac.rb +33 -0
- data/lib/sts/tbx_iso_tml/mi.rb +19 -0
- data/lib/sts/tbx_iso_tml/mrow.rb +46 -0
- data/lib/sts/tbx_iso_tml/mspace.rb +18 -0
- data/lib/sts/tbx_iso_tml/mstyle.rb +29 -0
- data/lib/sts/tbx_iso_tml/msub.rb +34 -0
- data/lib/sts/tbx_iso_tml/msup.rb +27 -0
- data/lib/sts/tbx_iso_tml/munder.rb +20 -0
- data/lib/sts/tbx_iso_tml/munderover.rb +24 -0
- data/lib/sts/tbx_iso_tml/named_content.rb +20 -0
- data/lib/sts/tbx_iso_tml/normative_authorization.rb +2 -2
- data/lib/sts/tbx_iso_tml/note.rb +31 -2
- data/lib/sts/tbx_iso_tml/part_of_speech.rb +2 -2
- data/lib/sts/tbx_iso_tml/see.rb +2 -2
- data/lib/sts/tbx_iso_tml/semantics.rb +29 -0
- data/lib/sts/tbx_iso_tml/source.rb +6 -1
- data/lib/sts/tbx_iso_tml/sup.rb +24 -0
- data/lib/sts/tbx_iso_tml/table.rb +32 -0
- data/lib/sts/tbx_iso_tml/table_wrap.rb +32 -0
- data/lib/sts/tbx_iso_tml/table_wrap_foot.rb +19 -0
- data/lib/sts/tbx_iso_tml/tbody.rb +26 -0
- data/lib/sts/tbx_iso_tml/td.rb +60 -0
- data/lib/sts/tbx_iso_tml/term.rb +31 -2
- data/lib/sts/tbx_iso_tml/term_entry.rb +2 -3
- data/lib/sts/tbx_iso_tml/term_information_group.rb +5 -2
- data/lib/sts/tbx_iso_tml/term_type.rb +2 -2
- data/lib/sts/tbx_iso_tml/th.rb +50 -0
- data/lib/sts/tbx_iso_tml/thead.rb +26 -0
- data/lib/sts/tbx_iso_tml/tr.rb +22 -0
- data/lib/sts/tbx_iso_tml/xref.rb +26 -0
- data/lib/sts/tbx_iso_tml.rb +8 -0
- data/lib/sts/version.rb +1 -1
- data/lib/sts.rb +1 -0
- data/sts.gemspec +2 -8
- metadata +61 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29fa738a2be8fa8ad9b9deac71cf0ff7e6e84fdb4f6fdeef1cc7695b4eb0848d
|
4
|
+
data.tar.gz: 3b2538ea0daeca072954ff6ff95c78ed43da784024de3151c6fc8ffca47fb552
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cc9dc6d6365b1c8bc92ba833a9064bf1e2e4961bad763655eaecf2ccdaa872622755a27308d292491b5a5b3803b74803630e944f86c21331eb11821ed47143b
|
7
|
+
data.tar.gz: 928162548cc113a5438b997c6b8ea208d91858b446e663a70ffacb7f7a16886fdf12cd21f8de2039b50e6ee21ca539b62e7667f973132b5edd47504e4aaa7f63
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -5,8 +5,14 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in sts.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
gem "pry", "~> 0.14.0"
|
9
|
+
|
8
10
|
gem "rake", "~> 13.0"
|
9
11
|
|
10
12
|
gem "rspec", "~> 3.0"
|
11
13
|
|
12
14
|
gem "rubocop", "~> 1.21"
|
15
|
+
|
16
|
+
gem "rubocop-performance", "~> 1.19"
|
17
|
+
|
18
|
+
gem "equivalent-xml", "~> 0.6"
|
data/lib/sts/mapper.rb
ADDED
@@ -0,0 +1,442 @@
|
|
1
|
+
# rubocop:disable AllCops
|
2
|
+
|
3
|
+
require "shale"
|
4
|
+
|
5
|
+
module Sts
|
6
|
+
class Mapper < Shale::Mapper
|
7
|
+
class << self
|
8
|
+
# Convert XML document to Object
|
9
|
+
#
|
10
|
+
# @param [Shale::Adapter::<XML adapter>::Node] element
|
11
|
+
# @param [Array<Symbol>] only
|
12
|
+
# @param [Array<Symbol>] except
|
13
|
+
# @param [any] context
|
14
|
+
#
|
15
|
+
# @return [model instance]
|
16
|
+
#
|
17
|
+
# @api public
|
18
|
+
def of_xml(element, only: nil, except: nil, context: nil)
|
19
|
+
instance = model.new
|
20
|
+
|
21
|
+
attributes
|
22
|
+
.values
|
23
|
+
.select { |attr| attr.default }
|
24
|
+
.each { |attr| instance.send(attr.setter, attr.default.call) }
|
25
|
+
|
26
|
+
grouping = Shale::Mapping::Group::XmlGrouping.new
|
27
|
+
delegates = Shale::Mapping::Delegates.new
|
28
|
+
|
29
|
+
only = to_partial_render_attributes(only)
|
30
|
+
except = to_partial_render_attributes(except)
|
31
|
+
|
32
|
+
element.attributes.each do |key, value|
|
33
|
+
mapping = xml_mapping.attributes[key.to_s]
|
34
|
+
next unless mapping
|
35
|
+
|
36
|
+
if mapping.group
|
37
|
+
grouping.add(mapping, :attribute, value)
|
38
|
+
elsif mapping.method_from
|
39
|
+
mapper = new
|
40
|
+
|
41
|
+
if mapper.method(mapping.method_from).arity == 3
|
42
|
+
mapper.send(mapping.method_from, instance, value, context)
|
43
|
+
else
|
44
|
+
mapper.send(mapping.method_from, instance, value)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
receiver_attributes = get_receiver_attributes(mapping)
|
48
|
+
attribute = receiver_attributes[mapping.attribute]
|
49
|
+
next unless attribute
|
50
|
+
|
51
|
+
next if only && !only.key?(attribute.name)
|
52
|
+
next if except&.key?(attribute.name)
|
53
|
+
|
54
|
+
casted_value = attribute.type.cast(value)
|
55
|
+
|
56
|
+
if attribute.collection?
|
57
|
+
if mapping.receiver
|
58
|
+
delegates.add_collection(
|
59
|
+
attributes[mapping.receiver],
|
60
|
+
attribute.setter,
|
61
|
+
casted_value
|
62
|
+
)
|
63
|
+
else
|
64
|
+
instance.send(attribute.name) << casted_value
|
65
|
+
end
|
66
|
+
elsif mapping.receiver
|
67
|
+
delegates.add(attributes[mapping.receiver], attribute.setter, casted_value)
|
68
|
+
else
|
69
|
+
instance.send(attribute.setter, casted_value)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
content_mapping = xml_mapping.content
|
75
|
+
|
76
|
+
if content_mapping
|
77
|
+
if content_mapping.group
|
78
|
+
grouping.add(content_mapping, :content, element)
|
79
|
+
elsif content_mapping.method_from
|
80
|
+
mapper = new
|
81
|
+
|
82
|
+
if mapper.method(content_mapping.method_from).arity == 3
|
83
|
+
mapper.send(content_mapping.method_from, instance, element, context)
|
84
|
+
else
|
85
|
+
mapper.send(content_mapping.method_from, instance, element)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
get_content_value(content_mapping, element, only, except, delegates, instance)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
element.instance_variable_get(:@node)&.children&.each do |nokogiri_node|
|
93
|
+
if nokogiri_node.name == "text"
|
94
|
+
next unless content_mapping
|
95
|
+
|
96
|
+
content_value = get_content_value(content_mapping, nokogiri_node, only, except, delegates, instance)
|
97
|
+
instance.all_content << ["content", content_value]
|
98
|
+
next
|
99
|
+
elsif nokogiri_node.name == "comment"
|
100
|
+
instance.all_content << ["comment", nokogiri_node.text]
|
101
|
+
next
|
102
|
+
end
|
103
|
+
|
104
|
+
node = element.class.new(nokogiri_node)
|
105
|
+
mapping = xml_mapping.elements[node.name]
|
106
|
+
|
107
|
+
next unless mapping
|
108
|
+
|
109
|
+
if mapping.group
|
110
|
+
grouping.add(mapping, :element, node)
|
111
|
+
elsif mapping.method_from
|
112
|
+
mapper = new
|
113
|
+
|
114
|
+
if mapper.method(mapping.method_from).arity == 3
|
115
|
+
mapper.send(mapping.method_from, instance, node, context)
|
116
|
+
else
|
117
|
+
mapper.send(mapping.method_from, instance, node)
|
118
|
+
end
|
119
|
+
else
|
120
|
+
receiver_attributes = get_receiver_attributes(mapping)
|
121
|
+
attribute = receiver_attributes[mapping.attribute]
|
122
|
+
next unless attribute
|
123
|
+
|
124
|
+
if only
|
125
|
+
attribute_only = only[attribute.name]
|
126
|
+
next unless only.key?(attribute.name)
|
127
|
+
end
|
128
|
+
|
129
|
+
if except
|
130
|
+
attribute_except = except[attribute.name]
|
131
|
+
next if except.key?(attribute.name) && attribute_except.nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
value = attribute.type.of_xml(
|
135
|
+
node,
|
136
|
+
only: attribute_only,
|
137
|
+
except: attribute_except,
|
138
|
+
context: context
|
139
|
+
)
|
140
|
+
|
141
|
+
casted_value = attribute.type.cast(value)
|
142
|
+
instance.all_content << [mapping, casted_value]
|
143
|
+
|
144
|
+
if attribute.collection?
|
145
|
+
if mapping.receiver
|
146
|
+
delegates.add_collection(
|
147
|
+
attributes[mapping.receiver],
|
148
|
+
attribute.setter,
|
149
|
+
casted_value
|
150
|
+
)
|
151
|
+
else
|
152
|
+
instance.send(attribute.name) << casted_value
|
153
|
+
end
|
154
|
+
elsif mapping.receiver
|
155
|
+
delegates.add(attributes[mapping.receiver], attribute.setter, casted_value)
|
156
|
+
else
|
157
|
+
instance.send(attribute.setter, casted_value)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
delegates.each do |delegate|
|
163
|
+
receiver = get_receiver(instance, delegate.receiver_attribute)
|
164
|
+
receiver.send(delegate.setter, delegate.value)
|
165
|
+
end
|
166
|
+
|
167
|
+
grouping.each do |group|
|
168
|
+
mapper = new
|
169
|
+
|
170
|
+
if mapper.method(group.method_from).arity == 3
|
171
|
+
mapper.send(group.method_from, instance, group.dict, context)
|
172
|
+
else
|
173
|
+
mapper.send(group.method_from, instance, group.dict)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
instance
|
178
|
+
end
|
179
|
+
|
180
|
+
# Convert Object to XML document
|
181
|
+
#
|
182
|
+
# @param [any] instance Object to convert
|
183
|
+
# @param [String, nil] node_name XML node name
|
184
|
+
# @param [Shale::Adapter::<xml adapter>::Document, nil] doc Object to convert
|
185
|
+
# @param [Array<Symbol>] only
|
186
|
+
# @param [Array<Symbol>] except
|
187
|
+
# @param [any] context
|
188
|
+
#
|
189
|
+
# @raise [IncorrectModelError]
|
190
|
+
#
|
191
|
+
# @return [::REXML::Document, ::Nokogiri::Document, ::Ox::Document]
|
192
|
+
#
|
193
|
+
# @api public
|
194
|
+
def as_xml(
|
195
|
+
instance,
|
196
|
+
node_name = nil,
|
197
|
+
doc = nil,
|
198
|
+
_cdata = nil,
|
199
|
+
only: nil,
|
200
|
+
except: nil,
|
201
|
+
context: nil,
|
202
|
+
version: nil
|
203
|
+
)
|
204
|
+
unless instance.is_a?(model)
|
205
|
+
msg = "argument is a '#{instance.class}' but should be a '#{model}'"
|
206
|
+
raise IncorrectModelError, msg
|
207
|
+
end
|
208
|
+
|
209
|
+
unless doc
|
210
|
+
doc = Shale.xml_adapter.create_document(version)
|
211
|
+
|
212
|
+
element = as_xml(
|
213
|
+
instance,
|
214
|
+
xml_mapping.prefixed_root,
|
215
|
+
doc,
|
216
|
+
only: only,
|
217
|
+
except: except,
|
218
|
+
context: context
|
219
|
+
)
|
220
|
+
doc.add_element(doc.doc, element)
|
221
|
+
|
222
|
+
return doc.doc
|
223
|
+
end
|
224
|
+
|
225
|
+
element = doc.create_element(node_name)
|
226
|
+
|
227
|
+
doc.add_namespace(
|
228
|
+
xml_mapping.default_namespace.prefix,
|
229
|
+
xml_mapping.default_namespace.name
|
230
|
+
)
|
231
|
+
|
232
|
+
grouping = Shale::Mapping::Group::XmlGrouping.new
|
233
|
+
|
234
|
+
only = to_partial_render_attributes(only)
|
235
|
+
except = to_partial_render_attributes(except)
|
236
|
+
|
237
|
+
xml_mapping.attributes.each_value do |mapping|
|
238
|
+
if mapping.group
|
239
|
+
grouping.add(mapping, :attribute, nil)
|
240
|
+
elsif mapping.method_to
|
241
|
+
mapper = new
|
242
|
+
|
243
|
+
if mapper.method(mapping.method_to).arity == 4
|
244
|
+
mapper.send(mapping.method_to, instance, element, doc, context)
|
245
|
+
else
|
246
|
+
mapper.send(mapping.method_to, instance, element, doc)
|
247
|
+
end
|
248
|
+
else
|
249
|
+
if mapping.receiver
|
250
|
+
receiver = instance.send(mapping.receiver)
|
251
|
+
else
|
252
|
+
receiver = instance
|
253
|
+
end
|
254
|
+
|
255
|
+
receiver_attributes = get_receiver_attributes(mapping)
|
256
|
+
attribute = receiver_attributes[mapping.attribute]
|
257
|
+
next unless attribute
|
258
|
+
|
259
|
+
next if only && !only.key?(attribute.name)
|
260
|
+
next if except&.key?(attribute.name)
|
261
|
+
|
262
|
+
value = receiver.send(attribute.name) if receiver
|
263
|
+
|
264
|
+
if mapping.render_nil? || !value.nil?
|
265
|
+
doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
|
266
|
+
doc.add_attribute(element, mapping.prefixed_name, value)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
instance.all_content.each do |mapping, content|
|
272
|
+
if mapping == "comment"
|
273
|
+
comment = Nokogiri::XML::Comment.new(doc.doc, content)
|
274
|
+
doc.add_element(element, comment)
|
275
|
+
elsif mapping == "content"
|
276
|
+
content_mapping = xml_mapping.content
|
277
|
+
if content_mapping
|
278
|
+
if content_mapping.group
|
279
|
+
grouping.add(content_mapping, :content, nil)
|
280
|
+
elsif content_mapping.method_to
|
281
|
+
mapper = new
|
282
|
+
|
283
|
+
if mapper.method(content_mapping.method_to).arity == 4
|
284
|
+
mapper.send(content_mapping.method_to, instance, element, doc, context)
|
285
|
+
else
|
286
|
+
mapper.send(content_mapping.method_to, instance, element, doc)
|
287
|
+
end
|
288
|
+
else
|
289
|
+
if content_mapping.receiver
|
290
|
+
receiver = instance.send(content_mapping.receiver)
|
291
|
+
else
|
292
|
+
receiver = instance
|
293
|
+
end
|
294
|
+
|
295
|
+
receiver_attributes = get_receiver_attributes(content_mapping)
|
296
|
+
attribute = receiver_attributes[content_mapping.attribute]
|
297
|
+
|
298
|
+
if attribute
|
299
|
+
skip = false
|
300
|
+
|
301
|
+
# rubocop:disable Metrics/BlockNesting
|
302
|
+
skip = true if only && !only.key?(attribute.name)
|
303
|
+
skip = true if except&.key?(attribute.name)
|
304
|
+
|
305
|
+
unless skip
|
306
|
+
# value = receiver.send(attribute.name) if receiver
|
307
|
+
value = content
|
308
|
+
|
309
|
+
if content_mapping.cdata
|
310
|
+
doc.create_cdata(value, element)
|
311
|
+
else
|
312
|
+
a = Nokogiri::XML::Text.new(value, doc.doc)
|
313
|
+
doc.add_element(element, a)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
# rubocop:enable Metrics/BlockNesting
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
else
|
321
|
+
if mapping.group
|
322
|
+
grouping.add(mapping, :element, nil)
|
323
|
+
elsif mapping.method_to
|
324
|
+
mapper = new
|
325
|
+
|
326
|
+
if mapper.method(mapping.method_to).arity == 4
|
327
|
+
mapper.send(mapping.method_to, instance, element, doc, context)
|
328
|
+
else
|
329
|
+
mapper.send(mapping.method_to, instance, element, doc)
|
330
|
+
end
|
331
|
+
else
|
332
|
+
if mapping.receiver
|
333
|
+
receiver = instance.send(mapping.receiver)
|
334
|
+
else
|
335
|
+
receiver = instance
|
336
|
+
end
|
337
|
+
|
338
|
+
receiver_attributes = get_receiver_attributes(mapping)
|
339
|
+
attribute = receiver_attributes[mapping.attribute]
|
340
|
+
next unless attribute
|
341
|
+
|
342
|
+
if only
|
343
|
+
attribute_only = only[attribute.name]
|
344
|
+
next unless only.key?(attribute.name)
|
345
|
+
end
|
346
|
+
|
347
|
+
if except
|
348
|
+
attribute_except = except[attribute.name]
|
349
|
+
next if except.key?(attribute.name) && attribute_except.nil?
|
350
|
+
end
|
351
|
+
|
352
|
+
value = content
|
353
|
+
|
354
|
+
if mapping.render_nil? || !value.nil?
|
355
|
+
doc.add_namespace(mapping.namespace.prefix, mapping.namespace.name)
|
356
|
+
end
|
357
|
+
|
358
|
+
if value.nil?
|
359
|
+
if mapping.render_nil?
|
360
|
+
child = doc.create_element(mapping.prefixed_name)
|
361
|
+
doc.add_element(element, child)
|
362
|
+
end
|
363
|
+
elsif attribute.collection?
|
364
|
+
[*value].each do |v|
|
365
|
+
next if v.nil?
|
366
|
+
child = attribute.type.as_xml(
|
367
|
+
v,
|
368
|
+
mapping.prefixed_name,
|
369
|
+
doc,
|
370
|
+
mapping.cdata,
|
371
|
+
only: attribute_only,
|
372
|
+
except: attribute_except,
|
373
|
+
context: context
|
374
|
+
)
|
375
|
+
doc.add_element(element, child)
|
376
|
+
end
|
377
|
+
else
|
378
|
+
child = attribute.type.as_xml(
|
379
|
+
value,
|
380
|
+
mapping.prefixed_name,
|
381
|
+
doc,
|
382
|
+
mapping.cdata,
|
383
|
+
only: attribute_only,
|
384
|
+
except: attribute_except,
|
385
|
+
context: context
|
386
|
+
)
|
387
|
+
doc.add_element(element, child)
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
grouping.each do |group|
|
394
|
+
mapper = new
|
395
|
+
|
396
|
+
if mapper.method(group.method_to).arity == 4
|
397
|
+
mapper.send(group.method_to, instance, element, doc, context)
|
398
|
+
else
|
399
|
+
mapper.send(group.method_to, instance, element, doc)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
element
|
404
|
+
end
|
405
|
+
|
406
|
+
def get_content_value(content_mapping, element, only, except, delegates, instance)
|
407
|
+
receiver_attributes = get_receiver_attributes(content_mapping)
|
408
|
+
attribute = receiver_attributes[content_mapping.attribute]
|
409
|
+
|
410
|
+
if attribute
|
411
|
+
skip = false
|
412
|
+
|
413
|
+
# rubocop:disable Metrics/BlockNesting
|
414
|
+
skip = true if only && !only.key?(attribute.name)
|
415
|
+
skip = true if except&.key?(attribute.name)
|
416
|
+
|
417
|
+
unless skip
|
418
|
+
value = attribute.type.cast(attribute.type.of_xml(element))
|
419
|
+
|
420
|
+
if content_mapping.receiver
|
421
|
+
delegates.add(attributes[content_mapping.receiver], attribute.setter, value)
|
422
|
+
else
|
423
|
+
instance.send(attribute.setter, value)
|
424
|
+
end
|
425
|
+
end
|
426
|
+
# rubocop:enable Metrics/BlockNesting
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
attr_accessor :all_content
|
432
|
+
|
433
|
+
def initialize
|
434
|
+
@all_content = []
|
435
|
+
|
436
|
+
super
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
# rubocop:enable AllCops
|
442
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../mapper"
|
4
|
+
|
5
|
+
require_relative "section"
|
6
|
+
require_relative "title"
|
7
|
+
require_relative "paragraph"
|
8
|
+
require_relative "non_normative_note"
|
9
|
+
require_relative "figure"
|
10
|
+
require_relative "reference_list"
|
11
|
+
require_relative "../tbx_iso_tml/table_wrap"
|
12
|
+
|
13
|
+
module Sts
|
14
|
+
module NisoSts
|
15
|
+
class Title < Sts::Mapper; end
|
16
|
+
class ReferenceList < Sts::Mapper; end
|
17
|
+
|
18
|
+
class App < Sts::Mapper
|
19
|
+
attribute :id, Shale::Type::String
|
20
|
+
attribute :content_type, Shale::Type::String
|
21
|
+
attribute :label, Shale::Type::String
|
22
|
+
attribute :annex_type, Shale::Type::String
|
23
|
+
attribute :title, Title
|
24
|
+
attribute :fig, Figure, collection: true
|
25
|
+
attribute :sec, Section, collection: true
|
26
|
+
attribute :paragraph, Paragraph, collection: true
|
27
|
+
attribute :ref_list, ReferenceList, collection: true
|
28
|
+
attribute :non_normative_note, NonNormativeNote, collection: true
|
29
|
+
attribute :table_wrap, Sts::TbxIsoTml::TableWrap, collection: true
|
30
|
+
|
31
|
+
xml do
|
32
|
+
root "app"
|
33
|
+
|
34
|
+
map_attribute "id", to: :id
|
35
|
+
map_attribute "content-type", to: :content_type
|
36
|
+
|
37
|
+
map_element "label", to: :label
|
38
|
+
map_element "annex-type", to: :annex_type
|
39
|
+
map_element "title", to: :title
|
40
|
+
map_element "sec", to: :sec
|
41
|
+
map_element "fig", to: :fig
|
42
|
+
map_element "p", to: :paragraph
|
43
|
+
map_element "ref-list", to: :ref_list
|
44
|
+
map_element "non-normative-note", to: :non_normative_note
|
45
|
+
map_element "table-wrap", to: :table_wrap
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../mapper"
|
4
|
+
|
5
|
+
require_relative "app"
|
6
|
+
|
7
|
+
module Sts
|
8
|
+
module NisoSts
|
9
|
+
class AppGroup < Sts::Mapper
|
10
|
+
attribute :app, Sts::NisoSts::App, collection: true
|
11
|
+
|
12
|
+
xml do
|
13
|
+
root "app-group"
|
14
|
+
|
15
|
+
map_element "app", to: :app
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/sts/niso_sts/back.rb
CHANGED
@@ -1,17 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "../mapper"
|
4
4
|
|
5
5
|
require_relative "reference_list"
|
6
|
+
require_relative "section"
|
7
|
+
require_relative "app_group"
|
8
|
+
require_relative "fn_group"
|
6
9
|
|
7
10
|
module Sts
|
8
11
|
module NisoSts
|
9
|
-
class Back <
|
12
|
+
class Back < Sts::Mapper
|
10
13
|
attribute :ref_list, ReferenceList
|
14
|
+
attribute :app_group, AppGroup
|
15
|
+
attribute :sec, Section
|
16
|
+
attribute :fn_group, FnGroup
|
11
17
|
|
12
18
|
xml do
|
13
19
|
root "back"
|
20
|
+
|
14
21
|
map_element "ref-list", to: :ref_list
|
22
|
+
map_element "app-group", to: :app_group
|
23
|
+
map_element "sec", to: :sec
|
24
|
+
map_element "fn-group", to: :fn_group
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
data/lib/sts/niso_sts/body.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "../mapper"
|
4
4
|
|
5
5
|
require_relative "section"
|
6
6
|
|
7
7
|
module Sts
|
8
8
|
module NisoSts
|
9
|
-
class Body <
|
9
|
+
class Body < Sts::Mapper
|
10
10
|
attribute :sec, Section, collection: true
|
11
11
|
|
12
12
|
xml do
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "../mapper"
|
2
|
+
|
3
|
+
require_relative "paragraph"
|
4
|
+
require_relative "title"
|
5
|
+
require_relative "non_normative_note"
|
6
|
+
|
7
|
+
# rubocop:disable Layout/LineLength
|
8
|
+
# <caption>
|
9
|
+
# <title>Overview of risk assessment/risk reduction</title>
|
10
|
+
# <p><def-list list-type="footnotes">
|
11
|
+
# <def-item>
|
12
|
+
# <term>a</term>
|
13
|
+
# <def>
|
14
|
+
# <p>Refers to <std><std-id-group>
|
15
|
+
# <std-id std-id-link-type="internal-pub-id" std-id-type="dated">e1d167f5</std-id>
|
16
|
+
# <std-id std-id-link-type="fpi" std-id-type="dated">+//ISO 9070/RA::A00007::GE::DIN German
|
17
|
+
# Institute for Standardization::Standards//DOCUMENT ISO 12100-1:2003-11-00//EN</std-id>
|
18
|
+
# </std-id-group>ISO 12100-1:2003</std>.</p>
|
19
|
+
# </def>
|
20
|
+
# </def-item>
|
21
|
+
# <def-item>
|
22
|
+
# <term>b</term>
|
23
|
+
# <def>
|
24
|
+
# <p>Refers to this part of ISO 13849.</p>
|
25
|
+
# </def>
|
26
|
+
# </def-item>
|
27
|
+
# </def-list></p>
|
28
|
+
# </caption>
|
29
|
+
# rubocop:enable Layout/LineLength
|
30
|
+
|
31
|
+
module Sts
|
32
|
+
module NisoSts
|
33
|
+
class Caption < Sts::Mapper
|
34
|
+
attribute :title, Title
|
35
|
+
attribute :paragraphs, Paragraph, collection: true
|
36
|
+
attribute :non_normative_note, NonNormativeNote, collection: true
|
37
|
+
|
38
|
+
xml do
|
39
|
+
root "caption"
|
40
|
+
|
41
|
+
map_element "p", to: :paragraphs
|
42
|
+
map_element "non-normative-note", to: :non_normative_note
|
43
|
+
map_element "title", to: :title
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../mapper"
|
4
|
+
|
5
|
+
module Sts
|
6
|
+
module NisoSts
|
7
|
+
class CustomMeta < Sts::Mapper
|
8
|
+
attribute :lang, Shale::Type::String
|
9
|
+
attribute :meta_name, Shale::Type::String
|
10
|
+
attribute :meta_value, Shale::Type::String
|
11
|
+
|
12
|
+
xml do
|
13
|
+
root "custom-meta"
|
14
|
+
|
15
|
+
map_attribute "lang", to: :lang,
|
16
|
+
namespace: "http://www.w3.org/XML/1998/namespace",
|
17
|
+
prefix: "xml"
|
18
|
+
map_element "meta-name", to: :meta_name
|
19
|
+
map_element "meta-value", to: :meta_value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../mapper"
|
4
|
+
|
5
|
+
require_relative "custom_meta"
|
6
|
+
|
7
|
+
module Sts
|
8
|
+
module NisoSts
|
9
|
+
class CustomMetaGroup < Sts::Mapper
|
10
|
+
attribute :custom_meta, CustomMeta, collection: true
|
11
|
+
|
12
|
+
xml do
|
13
|
+
root "custom-meta-group"
|
14
|
+
map_attribute "custom-meta", to: :custom_meta
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|