sts 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop-https---raw-githubusercontent-com-riboseinc-oss-guides-master-ci-rubocop-yml +471 -0
  3. data/.rubocop.yml +1 -0
  4. data/.rubocop_todo.yml +27 -0
  5. data/lib/sts/niso_sts/adoption.rb +4 -4
  6. data/lib/sts/niso_sts/app.rb +8 -8
  7. data/lib/sts/niso_sts/app_group.rb +2 -2
  8. data/lib/sts/niso_sts/back.rb +2 -2
  9. data/lib/sts/niso_sts/body.rb +2 -2
  10. data/lib/sts/niso_sts/caption.rb +3 -3
  11. data/lib/sts/niso_sts/custom_meta.rb +5 -5
  12. data/lib/sts/niso_sts/custom_meta_group.rb +2 -2
  13. data/lib/sts/niso_sts/def.rb +2 -2
  14. data/lib/sts/niso_sts/def_item.rb +3 -3
  15. data/lib/sts/niso_sts/def_list.rb +5 -5
  16. data/lib/sts/niso_sts/display_formula.rb +3 -5
  17. data/lib/sts/niso_sts/document_identification.rb +8 -8
  18. data/lib/sts/niso_sts/ext_link.rb +5 -5
  19. data/lib/sts/niso_sts/figure.rb +6 -6
  20. data/lib/sts/niso_sts/fn.rb +3 -3
  21. data/lib/sts/niso_sts/fn_group.rb +2 -2
  22. data/lib/sts/niso_sts/front.rb +2 -2
  23. data/lib/sts/niso_sts/graphic.rb +3 -3
  24. data/lib/sts/niso_sts/inline_formula.rb +2 -4
  25. data/lib/sts/niso_sts/label.rb +3 -3
  26. data/lib/sts/niso_sts/list.rb +4 -6
  27. data/lib/sts/niso_sts/list_item.rb +4 -4
  28. data/lib/sts/niso_sts/meta_date.rb +4 -4
  29. data/lib/sts/niso_sts/meta_note.rb +7 -6
  30. data/lib/sts/niso_sts/metadata_iso.rb +10 -10
  31. data/lib/sts/niso_sts/metadata_std.rb +12 -12
  32. data/lib/sts/niso_sts/mixed_citation.rb +8 -8
  33. data/lib/sts/niso_sts/non_normative_example.rb +5 -5
  34. data/lib/sts/niso_sts/non_normative_note.rb +5 -5
  35. data/lib/sts/niso_sts/object_id.rb +4 -4
  36. data/lib/sts/niso_sts/page_count.rb +3 -3
  37. data/lib/sts/niso_sts/paragraph.rb +12 -12
  38. data/lib/sts/niso_sts/permissions.rb +5 -5
  39. data/lib/sts/niso_sts/reference.rb +3 -5
  40. data/lib/sts/niso_sts/reference_list.rb +5 -7
  41. data/lib/sts/niso_sts/reference_standard.rb +7 -7
  42. data/lib/sts/niso_sts/section.rb +8 -8
  43. data/lib/sts/niso_sts/section_array.rb +3 -3
  44. data/lib/sts/niso_sts/standard.rb +6 -8
  45. data/lib/sts/niso_sts/standard_identification.rb +9 -9
  46. data/lib/sts/niso_sts/standard_ref.rb +4 -4
  47. data/lib/sts/niso_sts/std_cross_reference.rb +3 -3
  48. data/lib/sts/niso_sts/std_id.rb +6 -6
  49. data/lib/sts/niso_sts/std_id_group.rb +2 -2
  50. data/lib/sts/niso_sts/term_display.rb +2 -2
  51. data/lib/sts/niso_sts/term_section.rb +5 -5
  52. data/lib/sts/niso_sts/title.rb +4 -4
  53. data/lib/sts/niso_sts/title_wrap.rb +11 -9
  54. data/lib/sts/tbx_iso_tml/bold.rb +3 -3
  55. data/lib/sts/tbx_iso_tml/caption.rb +3 -3
  56. data/lib/sts/tbx_iso_tml/col.rb +6 -6
  57. data/lib/sts/tbx_iso_tml/definition.rb +5 -7
  58. data/lib/sts/tbx_iso_tml/entailed_term.rb +6 -6
  59. data/lib/sts/tbx_iso_tml/example.rb +6 -8
  60. data/lib/sts/tbx_iso_tml/external_graphic.rb +3 -3
  61. data/lib/sts/tbx_iso_tml/external_source.rb +4 -4
  62. data/lib/sts/tbx_iso_tml/fn.rb +3 -5
  63. data/lib/sts/tbx_iso_tml/fn_group.rb +2 -2
  64. data/lib/sts/tbx_iso_tml/geographical_usage.rb +3 -3
  65. data/lib/sts/tbx_iso_tml/grammatical_gender.rb +4 -4
  66. data/lib/sts/tbx_iso_tml/grammatical_number.rb +4 -4
  67. data/lib/sts/tbx_iso_tml/italic.rb +5 -5
  68. data/lib/sts/tbx_iso_tml/lang_set.rb +9 -9
  69. data/lib/sts/tbx_iso_tml/math.rb +12 -12
  70. data/lib/sts/tbx_iso_tml/mfenced.rb +10 -10
  71. data/lib/sts/tbx_iso_tml/mfrac.rb +8 -8
  72. data/lib/sts/tbx_iso_tml/mi.rb +3 -3
  73. data/lib/sts/tbx_iso_tml/mrow.rb +11 -11
  74. data/lib/sts/tbx_iso_tml/mspace.rb +3 -3
  75. data/lib/sts/tbx_iso_tml/mstyle.rb +8 -8
  76. data/lib/sts/tbx_iso_tml/msub.rb +7 -7
  77. data/lib/sts/tbx_iso_tml/msup.rb +5 -5
  78. data/lib/sts/tbx_iso_tml/munder.rb +3 -3
  79. data/lib/sts/tbx_iso_tml/munderover.rb +5 -5
  80. data/lib/sts/tbx_iso_tml/named_content.rb +4 -4
  81. data/lib/sts/tbx_iso_tml/normative_authorization.rb +4 -4
  82. data/lib/sts/tbx_iso_tml/note.rb +8 -8
  83. data/lib/sts/tbx_iso_tml/part_of_speech.rb +4 -4
  84. data/lib/sts/tbx_iso_tml/see.rb +4 -4
  85. data/lib/sts/tbx_iso_tml/semantics.rb +6 -5
  86. data/lib/sts/tbx_iso_tml/source.rb +4 -6
  87. data/lib/sts/tbx_iso_tml/sup.rb +4 -6
  88. data/lib/sts/tbx_iso_tml/table.rb +6 -6
  89. data/lib/sts/tbx_iso_tml/table_break.rb +10 -0
  90. data/lib/sts/tbx_iso_tml/table_wrap.rb +6 -6
  91. data/lib/sts/tbx_iso_tml/table_wrap_foot.rb +2 -2
  92. data/lib/sts/tbx_iso_tml/tbody.rb +5 -5
  93. data/lib/sts/tbx_iso_tml/td.rb +17 -15
  94. data/lib/sts/tbx_iso_tml/term.rb +10 -10
  95. data/lib/sts/tbx_iso_tml/term_entry.rb +4 -4
  96. data/lib/sts/tbx_iso_tml/term_information_group.rb +6 -6
  97. data/lib/sts/tbx_iso_tml/term_type.rb +4 -12
  98. data/lib/sts/tbx_iso_tml/th.rb +17 -16
  99. data/lib/sts/tbx_iso_tml/thead.rb +6 -6
  100. data/lib/sts/tbx_iso_tml/tr.rb +2 -2
  101. data/lib/sts/tbx_iso_tml/xref.rb +5 -7
  102. data/lib/sts/version.rb +1 -1
  103. data/lib/sts.rb +6 -4
  104. data/sts.gemspec +4 -1
  105. metadata +22 -5
  106. data/lib/sts/mapper.rb +0 -442
data/lib/sts/mapper.rb DELETED
@@ -1,442 +0,0 @@
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
-