relaton-itu 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ module RelatonItu
2
+ class StructuredIdentifier
3
+ # @return [String]
4
+ attr_reader :bureau, :docnumber
5
+
6
+ # @return [String, NilClass]
7
+ attr_reader :annexid
8
+
9
+ # @param bureau [String] T, D, or R
10
+ # @param docnumber [String]
11
+ # @param annexid [String, NilClass]
12
+ def initialize(bureau:, docnumber:, annexid: nil)
13
+ unless EditorialGroup::BUREAUS.include? bureau
14
+ warn "[relaton-itu] WARNING: invalid bureau: #{bureau}"
15
+ end
16
+ @bureau = bureau
17
+ @docnumber = docnumber
18
+ @annexid = annexid
19
+ end
20
+
21
+ # @param builder [Nokogiri::XML::Builder]
22
+ def to_xml(builder)
23
+ builder.structuredidentifier do |b|
24
+ b.bureau bureau
25
+ b.docnumber docnumber
26
+ b.annexid annexid if annexid
27
+ end
28
+ end
29
+
30
+ # @return [Hash]
31
+ def to_hash
32
+ hash = { bureau: bureau, docnumber: docnumber }
33
+ hash[:annexid] = annexid if annexid
34
+ hash
35
+ end
36
+
37
+ def presence?
38
+ true
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module RelatonItu
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.2.0".freeze
3
3
  end
@@ -1,23 +1,16 @@
1
1
  require "nokogiri"
2
2
 
3
3
  module RelatonItu
4
- class XMLParser < RelatonIsoBib::XMLParser
4
+ class XMLParser < RelatonBib::XMLParser
5
5
  class << self
6
- # Override RelatonIsoBib::XMLParser.form_xml method.
7
- # @param xml [String]
6
+ private
7
+
8
+ # @param item_hash [Hash]
8
9
  # @return [RelatonItu::ItuBibliographicItem]
9
- def from_xml(xml)
10
- doc = Nokogiri::XML(xml)
11
- ituitem = doc.at "/bibitem|/bibdata"
12
- if ituitem
13
- ItuBibliographicItem.new item_data(ituitem)
14
- elsif
15
- warn "[relaton-itu] can't find bibitem or bibdata element in the XML"
16
- end
10
+ def bib_item(item_hash)
11
+ ItuBibliographicItem.new item_hash
17
12
  end
18
13
 
19
- private
20
-
21
14
  # @param ext [Nokogiri::XML::Element]
22
15
  # @return [RelatonItu::EditorialGroup]
23
16
  def fetch_editorialgroup(ext)
@@ -54,6 +47,18 @@ module RelatonItu
54
47
  start: period.at("start").text, finish: period.at("end")&.text,
55
48
  )
56
49
  end
50
+
51
+ # @param ext [Nokogiri::XML::Element]
52
+ # @return [RelatonItu::StructuredIdentifier]
53
+ def fetch_structuredidentifier(ext)
54
+ sid = ext.at "./structuredidentifier"
55
+ return unless sid
56
+
57
+ br = sid.at("bureau").text
58
+ dn = sid.at("docnumber").text
59
+ an = sid.at("annexid")&.text
60
+ StructuredIdentifier.new(bureau: br, docnumber: dn, annexid: an)
61
+ end
57
62
  end
58
63
  end
59
64
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
23
  end
24
24
  spec.bindir = "exe"
@@ -37,5 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "vcr", "~> 5.0.0"
38
38
  spec.add_development_dependency "webmock"
39
39
 
40
- spec.add_dependency "relaton-iso-bib", "~> 1.0.0"
40
+ spec.add_dependency "relaton-bib", "~> 1.2.0"
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-itu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -151,19 +151,19 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: relaton-iso-bib
154
+ name: relaton-bib
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.0.0
159
+ version: 1.2.0
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.0.0
166
+ version: 1.2.0
167
167
  description: 'RelatonItu: retrieve ITU Standards for bibliographic use using the BibliographicItem
168
168
  model'
169
169
  email:
@@ -187,7 +187,6 @@ files:
187
187
  - grammars/basicdoc.rng
188
188
  - grammars/biblio.rng
189
189
  - grammars/isodoc.rng
190
- - grammars/isostandard.rng
191
190
  - grammars/itu.rng
192
191
  - grammars/reqt.rng
193
192
  - lib/relaton_itu.rb
@@ -200,6 +199,7 @@ files:
200
199
  - lib/relaton_itu/itu_group.rb
201
200
  - lib/relaton_itu/processor.rb
202
201
  - lib/relaton_itu/scrapper.rb
202
+ - lib/relaton_itu/structured_identifier.rb
203
203
  - lib/relaton_itu/version.rb
204
204
  - lib/relaton_itu/xml_parser.rb
205
205
  - relaton-itu.gemspec
@@ -1,522 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
- <!-- default namespace isostandard = "https://www.metanorma.com/ns/iso" -->
4
- <include href="isodoc.rng">
5
- <start>
6
- <ref name="iso-standard"/>
7
- </start>
8
- <define name="organization">
9
- <element name="organization">
10
- <oneOrMore>
11
- <ref name="orgname"/>
12
- </oneOrMore>
13
- <optional>
14
- <ref name="abbreviation"/>
15
- </optional>
16
- <optional>
17
- <ref name="uri"/>
18
- </optional>
19
- <zeroOrMore>
20
- <ref name="org-identifier"/>
21
- </zeroOrMore>
22
- <zeroOrMore>
23
- <ref name="contact"/>
24
- </zeroOrMore>
25
- <optional>
26
- <ref name="technical-committee"/>
27
- </optional>
28
- <optional>
29
- <ref name="subcommittee"/>
30
- </optional>
31
- <optional>
32
- <ref name="workgroup"/>
33
- </optional>
34
- <optional>
35
- <ref name="secretariat"/>
36
- </optional>
37
- </element>
38
- </define>
39
- <define name="BibDataExtensionType">
40
- <ref name="doctype"/>
41
- <ref name="editorialgroup"/>
42
- <zeroOrMore>
43
- <ref name="ics"/>
44
- </zeroOrMore>
45
- <ref name="structuredidentifier"/>
46
- <optional>
47
- <ref name="stagename"/>
48
- </optional>
49
- </define>
50
- <define name="bdate">
51
- <element name="date">
52
- <attribute name="type">
53
- <choice>
54
- <ref name="BibliographicDateType"/>
55
- <text/>
56
- </choice>
57
- </attribute>
58
- <choice>
59
- <group>
60
- <element name="from">
61
- <ref name="ISO8601Date"/>
62
- </element>
63
- <optional>
64
- <element name="to">
65
- <ref name="ISO8601Date"/>
66
- </element>
67
- </optional>
68
- </group>
69
- <element name="on">
70
- <choice>
71
- <ref name="ISO8601Date"/>
72
- <value>--</value>
73
- <value>–</value>
74
- </choice>
75
- </element>
76
- </choice>
77
- </element>
78
- </define>
79
- <define name="ul">
80
- <element name="ul">
81
- <attribute name="id">
82
- <data type="ID"/>
83
- </attribute>
84
- <oneOrMore>
85
- <ref name="ul_li"/>
86
- </oneOrMore>
87
- <zeroOrMore>
88
- <ref name="note"/>
89
- </zeroOrMore>
90
- </element>
91
- </define>
92
- <define name="sections">
93
- <element name="sections">
94
- <ref name="clause"/>
95
- <optional>
96
- <choice>
97
- <ref name="term-clause"/>
98
- <ref name="terms"/>
99
- </choice>
100
- </optional>
101
- <optional>
102
- <ref name="definitions"/>
103
- </optional>
104
- <oneOrMore>
105
- <ref name="clause"/>
106
- </oneOrMore>
107
- </element>
108
- </define>
109
- <define name="Clause-Section">
110
- <optional>
111
- <attribute name="id">
112
- <data type="ID"/>
113
- </attribute>
114
- </optional>
115
- <optional>
116
- <attribute name="language"/>
117
- </optional>
118
- <optional>
119
- <attribute name="script"/>
120
- </optional>
121
- <optional>
122
- <attribute name="inline-header">
123
- <data type="boolean"/>
124
- </attribute>
125
- </optional>
126
- <optional>
127
- <attribute name="obligation">
128
- <choice>
129
- <value>normative</value>
130
- <value>informative</value>
131
- </choice>
132
- </attribute>
133
- </optional>
134
- <optional>
135
- <ref name="section-title"/>
136
- </optional>
137
- <choice>
138
- <group>
139
- <oneOrMore>
140
- <ref name="BasicBlock"/>
141
- </oneOrMore>
142
- <zeroOrMore>
143
- <ref name="note"/>
144
- </zeroOrMore>
145
- </group>
146
- <oneOrMore>
147
- <ref name="clause-subsection"/>
148
- </oneOrMore>
149
- </choice>
150
- </define>
151
- <define name="term">
152
- <element name="term">
153
- <optional>
154
- <attribute name="id">
155
- <data type="ID"/>
156
- </attribute>
157
- </optional>
158
- <ref name="preferred"/>
159
- <zeroOrMore>
160
- <ref name="admitted"/>
161
- </zeroOrMore>
162
- <zeroOrMore>
163
- <ref name="deprecates"/>
164
- </zeroOrMore>
165
- <optional>
166
- <ref name="termdomain"/>
167
- </optional>
168
- <ref name="definition"/>
169
- <zeroOrMore>
170
- <ref name="termnote"/>
171
- </zeroOrMore>
172
- <zeroOrMore>
173
- <ref name="termexample"/>
174
- </zeroOrMore>
175
- <zeroOrMore>
176
- <ref name="termsource"/>
177
- </zeroOrMore>
178
- </element>
179
- </define>
180
- <define name="definition">
181
- <element name="definition">
182
- <oneOrMore>
183
- <choice>
184
- <ref name="paragraph"/>
185
- <ref name="figure"/>
186
- <ref name="formula"/>
187
- </choice>
188
- </oneOrMore>
189
- </element>
190
- </define>
191
- <define name="annex">
192
- <element name="annex">
193
- <optional>
194
- <attribute name="id">
195
- <data type="ID"/>
196
- </attribute>
197
- </optional>
198
- <optional>
199
- <attribute name="language"/>
200
- </optional>
201
- <optional>
202
- <attribute name="script"/>
203
- </optional>
204
- <optional>
205
- <attribute name="inline-header">
206
- <data type="boolean"/>
207
- </attribute>
208
- </optional>
209
- <optional>
210
- <attribute name="obligation">
211
- <choice>
212
- <value>normative</value>
213
- <value>informative</value>
214
- </choice>
215
- </attribute>
216
- </optional>
217
- <optional>
218
- <ref name="section-title"/>
219
- </optional>
220
- <zeroOrMore>
221
- <!--
222
- allow hanging paragraps in annexes: they introduce lists
223
- ( paragraph-with-footnote | table | note | formula | admonition | ol | ul | dl | figure | quote | sourcecode | review | example )*,
224
- -->
225
- <ref name="BasicBlock"/>
226
- </zeroOrMore>
227
- <zeroOrMore>
228
- <ref name="note"/>
229
- </zeroOrMore>
230
- <zeroOrMore>
231
- <ref name="clause-hanging-paragraph-with-footnote"/>
232
- </zeroOrMore>
233
- <zeroOrMore>
234
- <ref name="annex-appendix"/>
235
- </zeroOrMore>
236
- </element>
237
- </define>
238
- <define name="AdmonitionType">
239
- <choice>
240
- <value>danger</value>
241
- <value>caution</value>
242
- <value>warning</value>
243
- <value>important</value>
244
- <value>safety precautions</value>
245
- </choice>
246
- </define>
247
- <define name="preface">
248
- <element name="preface">
249
- <optional>
250
- <ref name="preface_abstract"/>
251
- </optional>
252
- <ref name="foreword"/>
253
- <optional>
254
- <ref name="introduction"/>
255
- </optional>
256
- </element>
257
- </define>
258
- <define name="DocumentType">
259
- <choice>
260
- <value>international-standard</value>
261
- <value>technical-specification</value>
262
- <value>technical-report</value>
263
- <value>publicly-available-specification</value>
264
- <value>international-workshop-agreement</value>
265
- <value>guide</value>
266
- </choice>
267
- </define>
268
- <define name="structuredidentifier">
269
- <element name="structuredidentifier">
270
- <optional>
271
- <attribute name="type"/>
272
- </optional>
273
- <group>
274
- <ref name="documentnumber"/>
275
- <optional>
276
- <ref name="tc-documentnumber"/>
277
- </optional>
278
- </group>
279
- </element>
280
- </define>
281
- <define name="foreword">
282
- <element name="foreword">
283
- <ref name="Basic-Section"/>
284
- </element>
285
- </define>
286
- <define name="introduction">
287
- <element name="introduction">
288
- <ref name="Content-Section"/>
289
- </element>
290
- </define>
291
- <define name="editorialgroup">
292
- <element name="editorialgroup">
293
- <oneOrMore>
294
- <ref name="technical-committee"/>
295
- </oneOrMore>
296
- <zeroOrMore>
297
- <ref name="subcommittee"/>
298
- </zeroOrMore>
299
- <zeroOrMore>
300
- <ref name="workgroup"/>
301
- </zeroOrMore>
302
- <optional>
303
- <ref name="secretariat"/>
304
- </optional>
305
- </element>
306
- </define>
307
- <define name="Content-Section">
308
- <optional>
309
- <attribute name="id">
310
- <data type="ID"/>
311
- </attribute>
312
- </optional>
313
- <optional>
314
- <attribute name="language"/>
315
- </optional>
316
- <optional>
317
- <attribute name="script"/>
318
- </optional>
319
- <optional>
320
- <attribute name="obligation">
321
- <choice>
322
- <value>normative</value>
323
- <value>informative</value>
324
- </choice>
325
- </attribute>
326
- </optional>
327
- <optional>
328
- <ref name="section-title"/>
329
- </optional>
330
- <choice>
331
- <group>
332
- <zeroOrMore>
333
- <ref name="BasicBlock"/>
334
- </zeroOrMore>
335
- <zeroOrMore>
336
- <ref name="note"/>
337
- </zeroOrMore>
338
- </group>
339
- <oneOrMore>
340
- <ref name="content-subsection"/>
341
- </oneOrMore>
342
- </choice>
343
- </define>
344
- <define name="table">
345
- <element name="table">
346
- <attribute name="id">
347
- <data type="ID"/>
348
- </attribute>
349
- <optional>
350
- <attribute name="width"/>
351
- </optional>
352
- <optional>
353
- <attribute name="unnumbered">
354
- <data type="boolean"/>
355
- </attribute>
356
- </optional>
357
- <optional>
358
- <attribute name="subsequence"/>
359
- </optional>
360
- <optional>
361
- <attribute name="alt"/>
362
- </optional>
363
- <optional>
364
- <attribute name="summary"/>
365
- </optional>
366
- <optional>
367
- <attribute name="uri">
368
- <data type="anyURI"/>
369
- </attribute>
370
- </optional>
371
- <optional>
372
- <ref name="tname"/>
373
- </optional>
374
- <optional>
375
- <ref name="thead"/>
376
- </optional>
377
- <ref name="tbody"/>
378
- <optional>
379
- <ref name="tfoot"/>
380
- </optional>
381
- <zeroOrMore>
382
- <ref name="table-note"/>
383
- </zeroOrMore>
384
- <optional>
385
- <ref name="dl"/>
386
- </optional>
387
- </element>
388
- </define>
389
- </include>
390
- <!-- end overrides -->
391
- <!--
392
- We display the Normative References between scope and terms; but to keep the
393
- grammar simple, we keep the references together
394
- -->
395
- <define name="iso-standard">
396
- <element name="iso-standard">
397
- <ref name="bibdata"/>
398
- <zeroOrMore>
399
- <ref name="termdocsource"/>
400
- </zeroOrMore>
401
- <optional>
402
- <ref name="boilerplate"/>
403
- </optional>
404
- <ref name="preface"/>
405
- <oneOrMore>
406
- <ref name="sections"/>
407
- </oneOrMore>
408
- <zeroOrMore>
409
- <ref name="annex"/>
410
- </zeroOrMore>
411
- <ref name="bibliography"/>
412
- </element>
413
- </define>
414
- <define name="documentnumber">
415
- <element name="project-number">
416
- <optional>
417
- <attribute name="part">
418
- <data type="int"/>
419
- </attribute>
420
- </optional>
421
- <optional>
422
- <attribute name="subpart">
423
- <data type="int"/>
424
- </attribute>
425
- </optional>
426
- <text/>
427
- </element>
428
- </define>
429
- <define name="tc-documentnumber">
430
- <element name="tc-document-number">
431
- <data type="int"/>
432
- </element>
433
- </define>
434
- <define name="subcommittee">
435
- <element name="subcommittee">
436
- <ref name="IsoWorkgroup"/>
437
- </element>
438
- </define>
439
- <define name="workgroup">
440
- <element name="workgroup">
441
- <ref name="IsoWorkgroup"/>
442
- </element>
443
- </define>
444
- <define name="secretariat">
445
- <element name="secretariat">
446
- <text/>
447
- </element>
448
- </define>
449
- <define name="clause-hanging-paragraph-with-footnote">
450
- <element name="clause">
451
- <optional>
452
- <attribute name="id">
453
- <data type="ID"/>
454
- </attribute>
455
- </optional>
456
- <optional>
457
- <attribute name="language"/>
458
- </optional>
459
- <optional>
460
- <attribute name="script"/>
461
- </optional>
462
- <optional>
463
- <attribute name="inline-header">
464
- <data type="boolean"/>
465
- </attribute>
466
- </optional>
467
- <optional>
468
- <attribute name="obligation">
469
- <choice>
470
- <value>normative</value>
471
- <value>informative</value>
472
- </choice>
473
- </attribute>
474
- </optional>
475
- <optional>
476
- <ref name="section-title"/>
477
- </optional>
478
- <zeroOrMore>
479
- <!-- allow hanging paragraphs in annexes: they introduce lists -->
480
- <ref name="BasicBlock"/>
481
- </zeroOrMore>
482
- <zeroOrMore>
483
- <ref name="note"/>
484
- </zeroOrMore>
485
- <zeroOrMore>
486
- <ref name="clause-hanging-paragraph-with-footnote"/>
487
- </zeroOrMore>
488
- </element>
489
- </define>
490
- <define name="annex-appendix">
491
- <element name="appendix">
492
- <ref name="Clause-Section"/>
493
- </element>
494
- </define>
495
- <define name="ul_li">
496
- <element name="li">
497
- <optional>
498
- <attribute name="id">
499
- <data type="ID"/>
500
- </attribute>
501
- </optional>
502
- <optional>
503
- <attribute name="uncheckedcheckbox">
504
- <data type="boolean"/>
505
- </attribute>
506
- </optional>
507
- <optional>
508
- <attribute name="checkedcheckbox">
509
- <data type="boolean"/>
510
- </attribute>
511
- </optional>
512
- <oneOrMore>
513
- <ref name="paragraph-with-footnote"/>
514
- </oneOrMore>
515
- </element>
516
- </define>
517
- <define name="stagename">
518
- <element name="stagename">
519
- <text/>
520
- </element>
521
- </define>
522
- </grammar>