relaton-bsi 1.11.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3111f0bbfe4aae50b70dbe3b55e5b3b8111eded6d6e808ced57dc1cec958115b
4
- data.tar.gz: 4b78d3666be1b4a5c765d18617112fe11735ab3e6323d26d8e96936e73c0ef65
3
+ metadata.gz: 7c8385792442a0ff58466ad73208254df767e7f92943965a109df5b77a8c247f
4
+ data.tar.gz: fecf1179508ec2c81e7eb061724fb35900a6153c1556240165b2a26b5abf6d8d
5
5
  SHA512:
6
- metadata.gz: f99e7b8408752f33397540fd8b4094505af023a47090ea737a80d4c723146eb97b0858c7bec74677a05a0824168bdfd4151c0e05985905907e2f85367d6b880b
7
- data.tar.gz: c14c76eaca4b46d77af4876d085d694118c19ea7226d40c8d171bd44bdb66f9295e98815e3af29876ce1a4ae4c3042a2715697102721402d49e2b096a422ccf4
6
+ metadata.gz: e812c7ae713cd9be63f21efbb8f00f5c54fe981a1dd05732a823266b12d9c0dc8cb0d8690d27b1716942d275d06fa94f4b196861d5c00e548201bb246d2692fb
7
+ data.tar.gz: fd959ac8c3292c9d8c018f885a1d374b30f0a8bcdd05628231453644c61db6f1302068614d0d20fc0bf077ade631d11196ee2021026ba49a98527ea1b3f5827e
@@ -10,27 +10,4 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
- runs-on: ${{ matrix.os }}
15
- continue-on-error: ${{ matrix.experimental }}
16
- strategy:
17
- fail-fast: false
18
- matrix:
19
- ruby: [ '3.0', '2.7', '2.6', '2.5' ]
20
- os: [ ubuntu-latest, windows-latest, macos-latest ]
21
- experimental: [ false ]
22
- steps:
23
- - uses: actions/checkout@v2
24
- with:
25
- submodules: true
26
-
27
- # https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
28
- - if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
29
- run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
30
-
31
- - uses: ruby/setup-ruby@v1
32
- with:
33
- ruby-version: ${{ matrix.ruby }}
34
- bundler-cache: true
35
-
36
- - run: bundle exec rake
13
+ uses: relaton/support/.github/workflows/rake.yml@master
data/grammars/biblio.rng CHANGED
@@ -225,9 +225,9 @@
225
225
  <zeroOrMore>
226
226
  <ref name="forename"/>
227
227
  </zeroOrMore>
228
- <zeroOrMore>
229
- <ref name="initial"/>
230
- </zeroOrMore>
228
+ <optional>
229
+ <ref name="formatted-initials"/>
230
+ </optional>
231
231
  <ref name="surname"/>
232
232
  <zeroOrMore>
233
233
  <ref name="addition"/>
@@ -247,8 +247,8 @@
247
247
  <ref name="LocalizedString"/>
248
248
  </element>
249
249
  </define>
250
- <define name="initial">
251
- <element name="initial">
250
+ <define name="formatted-initials">
251
+ <element name="formatted-initials">
252
252
  <ref name="LocalizedString"/>
253
253
  </element>
254
254
  </define>
@@ -264,6 +264,9 @@
264
264
  </define>
265
265
  <define name="forename">
266
266
  <element name="forename">
267
+ <optional>
268
+ <attribute name="initial"/>
269
+ </optional>
267
270
  <ref name="LocalizedString"/>
268
271
  </element>
269
272
  </define>
@@ -527,7 +530,7 @@
527
530
  </define>
528
531
  <define name="LocalityType">
529
532
  <data type="string">
530
- <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
533
+ <param name="pattern">section|clause|part|paragraph|chapter|page|title|line|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
531
534
  </data>
532
535
  </define>
533
536
  <define name="referenceFrom">
@@ -614,12 +617,103 @@
614
617
  <optional>
615
618
  <ref name="fetched"/>
616
619
  </optional>
617
- <choice>
618
- <oneOrMore>
619
- <ref name="btitle"/>
620
- </oneOrMore>
620
+ <optional>
621
621
  <ref name="formattedref"/>
622
- </choice>
622
+ </optional>
623
+ <oneOrMore>
624
+ <ref name="btitle"/>
625
+ </oneOrMore>
626
+ <zeroOrMore>
627
+ <ref name="bsource"/>
628
+ </zeroOrMore>
629
+ <oneOrMore>
630
+ <ref name="docidentifier"/>
631
+ </oneOrMore>
632
+ <optional>
633
+ <ref name="docnumber"/>
634
+ </optional>
635
+ <zeroOrMore>
636
+ <ref name="bdate"/>
637
+ </zeroOrMore>
638
+ <zeroOrMore>
639
+ <ref name="contributor"/>
640
+ </zeroOrMore>
641
+ <optional>
642
+ <ref name="edition"/>
643
+ </optional>
644
+ <zeroOrMore>
645
+ <ref name="version"/>
646
+ </zeroOrMore>
647
+ <zeroOrMore>
648
+ <ref name="biblionote"/>
649
+ </zeroOrMore>
650
+ <zeroOrMore>
651
+ <ref name="language"/>
652
+ </zeroOrMore>
653
+ <zeroOrMore>
654
+ <ref name="script"/>
655
+ </zeroOrMore>
656
+ <zeroOrMore>
657
+ <ref name="bibabstract"/>
658
+ </zeroOrMore>
659
+ <optional>
660
+ <ref name="status"/>
661
+ </optional>
662
+ <zeroOrMore>
663
+ <ref name="copyright"/>
664
+ </zeroOrMore>
665
+ <zeroOrMore>
666
+ <ref name="docrelation"/>
667
+ </zeroOrMore>
668
+ <zeroOrMore>
669
+ <ref name="series"/>
670
+ </zeroOrMore>
671
+ <optional>
672
+ <ref name="medium"/>
673
+ </optional>
674
+ <zeroOrMore>
675
+ <ref name="bplace"/>
676
+ </zeroOrMore>
677
+ <zeroOrMore>
678
+ <ref name="bprice"/>
679
+ </zeroOrMore>
680
+ <zeroOrMore>
681
+ <ref name="extent"/>
682
+ </zeroOrMore>
683
+ <optional>
684
+ <ref name="bibliographic_size"/>
685
+ </optional>
686
+ <zeroOrMore>
687
+ <ref name="accesslocation"/>
688
+ </zeroOrMore>
689
+ <zeroOrMore>
690
+ <ref name="license"/>
691
+ </zeroOrMore>
692
+ <zeroOrMore>
693
+ <ref name="bclassification"/>
694
+ </zeroOrMore>
695
+ <zeroOrMore>
696
+ <ref name="bkeyword"/>
697
+ </zeroOrMore>
698
+ <optional>
699
+ <ref name="validity"/>
700
+ </optional>
701
+ </define>
702
+ <define name="ReducedBibliographicItem">
703
+ <optional>
704
+ <attribute name="type">
705
+ <ref name="BibItemType"/>
706
+ </attribute>
707
+ </optional>
708
+ <optional>
709
+ <ref name="fetched"/>
710
+ </optional>
711
+ <optional>
712
+ <ref name="formattedref"/>
713
+ </optional>
714
+ <zeroOrMore>
715
+ <ref name="btitle"/>
716
+ </zeroOrMore>
623
717
  <zeroOrMore>
624
718
  <ref name="bsource"/>
625
719
  </zeroOrMore>
@@ -638,9 +732,9 @@
638
732
  <optional>
639
733
  <ref name="edition"/>
640
734
  </optional>
641
- <optional>
735
+ <zeroOrMore>
642
736
  <ref name="version"/>
643
- </optional>
737
+ </zeroOrMore>
644
738
  <zeroOrMore>
645
739
  <ref name="biblionote"/>
646
740
  </zeroOrMore>
@@ -833,6 +927,12 @@
833
927
  <data type="boolean"/>
834
928
  </attribute>
835
929
  </optional>
930
+ <optional>
931
+ <attribute name="language"/>
932
+ </optional>
933
+ <optional>
934
+ <attribute name="script"/>
935
+ </optional>
836
936
  <text/>
837
937
  </element>
838
938
  </define>
@@ -851,17 +951,46 @@
851
951
  </define>
852
952
  <define name="bplace">
853
953
  <element name="place">
854
- <optional>
855
- <attribute name="uri">
856
- <data type="anyURI"/>
857
- </attribute>
858
- </optional>
859
- <optional>
860
- <attribute name="region"/>
861
- </optional>
954
+ <choice>
955
+ <text/>
956
+ <group>
957
+ <ref name="bibliocity"/>
958
+ <zeroOrMore>
959
+ <ref name="biblioregion"/>
960
+ </zeroOrMore>
961
+ <zeroOrMore>
962
+ <ref name="bibliocountry"/>
963
+ </zeroOrMore>
964
+ </group>
965
+ </choice>
966
+ </element>
967
+ </define>
968
+ <define name="bibliocity">
969
+ <element name="city">
862
970
  <text/>
863
971
  </element>
864
972
  </define>
973
+ <define name="biblioregion">
974
+ <element name="region">
975
+ <ref name="RegionType"/>
976
+ </element>
977
+ </define>
978
+ <define name="bibliocountry">
979
+ <element name="country">
980
+ <ref name="RegionType"/>
981
+ </element>
982
+ </define>
983
+ <define name="RegionType">
984
+ <optional>
985
+ <attribute name="iso"/>
986
+ </optional>
987
+ <optional>
988
+ <attribute name="recommended">
989
+ <data type="boolean"/>
990
+ </attribute>
991
+ </optional>
992
+ <text/>
993
+ </define>
865
994
  <define name="bprice">
866
995
  <element name="price">
867
996
  <attribute name="currency"/>
@@ -957,36 +1086,34 @@
957
1086
  <ref name="SeriesType"/>
958
1087
  </attribute>
959
1088
  </optional>
960
- <choice>
1089
+ <optional>
961
1090
  <ref name="formattedref"/>
962
- <group>
963
- <ref name="btitle"/>
964
- <optional>
965
- <ref name="bplace"/>
966
- </optional>
967
- <optional>
968
- <ref name="seriesorganization"/>
969
- </optional>
970
- <optional>
971
- <ref name="abbreviation"/>
972
- </optional>
973
- <optional>
974
- <ref name="seriesfrom"/>
975
- </optional>
976
- <optional>
977
- <ref name="seriesto"/>
978
- </optional>
979
- <optional>
980
- <ref name="seriesnumber"/>
981
- </optional>
982
- <optional>
983
- <ref name="seriespartnumber"/>
984
- </optional>
985
- <optional>
986
- <ref name="seriesrun"/>
987
- </optional>
988
- </group>
989
- </choice>
1091
+ </optional>
1092
+ <ref name="btitle"/>
1093
+ <optional>
1094
+ <ref name="bplace"/>
1095
+ </optional>
1096
+ <optional>
1097
+ <ref name="seriesorganization"/>
1098
+ </optional>
1099
+ <optional>
1100
+ <ref name="abbreviation"/>
1101
+ </optional>
1102
+ <optional>
1103
+ <ref name="seriesfrom"/>
1104
+ </optional>
1105
+ <optional>
1106
+ <ref name="seriesto"/>
1107
+ </optional>
1108
+ <optional>
1109
+ <ref name="seriesnumber"/>
1110
+ </optional>
1111
+ <optional>
1112
+ <ref name="seriespartnumber"/>
1113
+ </optional>
1114
+ <optional>
1115
+ <ref name="seriesrun"/>
1116
+ </optional>
990
1117
  </element>
991
1118
  </define>
992
1119
  <define name="SeriesType">
@@ -1145,7 +1272,7 @@
1145
1272
  </element>
1146
1273
  </optional>
1147
1274
  <element name="bibitem">
1148
- <ref name="BibliographicItem"/>
1275
+ <ref name="ReducedBibliographicItem"/>
1149
1276
  </element>
1150
1277
  <choice>
1151
1278
  <zeroOrMore>
@@ -1170,9 +1297,9 @@
1170
1297
  <optional>
1171
1298
  <ref name="revision-date"/>
1172
1299
  </optional>
1173
- <zeroOrMore>
1300
+ <optional>
1174
1301
  <ref name="draft"/>
1175
- </zeroOrMore>
1302
+ </optional>
1176
1303
  </element>
1177
1304
  </define>
1178
1305
  <define name="vedition">
data/grammars/bsi.rng CHANGED
@@ -21,6 +21,7 @@
21
21
  <value>industry-technical-agreement</value>
22
22
  <value>standard</value>
23
23
  <value>european-workshop-agreement</value>
24
+ <value>fast-track-standard</value>
24
25
  </choice>
25
26
  </define>
26
27
  <define name="DocumentSubtype">
@@ -70,6 +71,16 @@
70
71
  <data type="anyURI"/>
71
72
  </attribute>
72
73
  </optional>
74
+ <optional>
75
+ <attribute name="coverpage">
76
+ <data type="boolean"/>
77
+ </attribute>
78
+ </optional>
79
+ <optional>
80
+ <attribute name="notag">
81
+ <data type="boolean"/>
82
+ </attribute>
83
+ </optional>
73
84
  <optional>
74
85
  <ref name="tname"/>
75
86
  </optional>
data/grammars/isodoc.rng CHANGED
@@ -32,6 +32,54 @@
32
32
  <ref name="DocumentType"/>
33
33
  </element>
34
34
  </define>
35
+ <define name="admonition">
36
+ <element name="admonition">
37
+ <attribute name="type">
38
+ <ref name="AdmonitionType"/>
39
+ </attribute>
40
+ <optional>
41
+ <attribute name="class"/>
42
+ </optional>
43
+ <attribute name="id">
44
+ <data type="ID"/>
45
+ </attribute>
46
+ <optional>
47
+ <attribute name="uri">
48
+ <data type="anyURI"/>
49
+ </attribute>
50
+ </optional>
51
+ <optional>
52
+ <attribute name="coverpage">
53
+ <data type="boolean"/>
54
+ </attribute>
55
+ </optional>
56
+ <optional>
57
+ <attribute name="notag">
58
+ <data type="boolean"/>
59
+ </attribute>
60
+ </optional>
61
+ <optional>
62
+ <ref name="tname"/>
63
+ </optional>
64
+ <zeroOrMore>
65
+ <ref name="paragraph-with-footnote"/>
66
+ </zeroOrMore>
67
+ <zeroOrMore>
68
+ <ref name="note"/>
69
+ </zeroOrMore>
70
+ </element>
71
+ </define>
72
+ <define name="AdmonitionType">
73
+ <choice>
74
+ <value>warning</value>
75
+ <value>note</value>
76
+ <value>tip</value>
77
+ <value>important</value>
78
+ <value>caution</value>
79
+ <value>statement</value>
80
+ <value>editorial</value>
81
+ </choice>
82
+ </define>
35
83
  <define name="index">
36
84
  <element name="index">
37
85
  <optional>
@@ -79,6 +127,11 @@
79
127
  <data type="boolean"/>
80
128
  </attribute>
81
129
  </optional>
130
+ <optional>
131
+ <attribute name="suppress_identifier">
132
+ <data type="boolean"/>
133
+ </attribute>
134
+ </optional>
82
135
  <ref name="BibliographicItem"/>
83
136
  </element>
84
137
  </define>
@@ -245,6 +298,9 @@
245
298
  <ref name="MultilingualRenderingType"/>
246
299
  </attribute>
247
300
  </optional>
301
+ <optional>
302
+ <ref name="tname"/>
303
+ </optional>
248
304
  <oneOrMore>
249
305
  <ref name="ul_li"/>
250
306
  </oneOrMore>
@@ -287,6 +343,9 @@
287
343
  </choice>
288
344
  </attribute>
289
345
  </optional>
346
+ <optional>
347
+ <ref name="tname"/>
348
+ </optional>
290
349
  <oneOrMore>
291
350
  <ref name="li"/>
292
351
  </oneOrMore>
@@ -323,6 +382,9 @@
323
382
  <ref name="MultilingualRenderingType"/>
324
383
  </attribute>
325
384
  </optional>
385
+ <optional>
386
+ <ref name="tname"/>
387
+ </optional>
326
388
  <oneOrMore>
327
389
  <ref name="dt"/>
328
390
  <ref name="dd"/>
@@ -657,6 +719,9 @@
657
719
  <optional>
658
720
  <attribute name="tag"/>
659
721
  </optional>
722
+ <optional>
723
+ <attribute name="type"/>
724
+ </optional>
660
725
  <optional>
661
726
  <attribute name="multilingual-rendering">
662
727
  <ref name="MultilingualRenderingType"/>
@@ -692,6 +757,9 @@
692
757
  <optional>
693
758
  <attribute name="tag"/>
694
759
  </optional>
760
+ <optional>
761
+ <attribute name="type"/>
762
+ </optional>
695
763
  <optional>
696
764
  <attribute name="multilingual-rendering">
697
765
  <ref name="MultilingualRenderingType"/>
@@ -851,6 +919,16 @@
851
919
  <ref name="MultilingualRenderingType"/>
852
920
  </attribute>
853
921
  </optional>
922
+ <optional>
923
+ <attribute name="coverpage">
924
+ <data type="boolean"/>
925
+ </attribute>
926
+ </optional>
927
+ <optional>
928
+ <attribute name="notag">
929
+ <data type="boolean"/>
930
+ </attribute>
931
+ </optional>
854
932
  <oneOrMore>
855
933
  <choice>
856
934
  <ref name="paragraph"/>
@@ -1178,6 +1256,7 @@
1178
1256
  <ref name="concept"/>
1179
1257
  <ref name="add"/>
1180
1258
  <ref name="del"/>
1259
+ <ref name="span"/>
1181
1260
  </choice>
1182
1261
  </define>
1183
1262
  <define name="add">
@@ -1204,6 +1283,19 @@
1204
1283
  </choice>
1205
1284
  </element>
1206
1285
  </define>
1286
+ <define name="span">
1287
+ <element name="span">
1288
+ <optional>
1289
+ <attribute name="class"/>
1290
+ </optional>
1291
+ <optional>
1292
+ <attribute name="style"/>
1293
+ </optional>
1294
+ <oneOrMore>
1295
+ <ref name="TextElement"/>
1296
+ </oneOrMore>
1297
+ </element>
1298
+ </define>
1207
1299
  <define name="concept">
1208
1300
  <element name="concept">
1209
1301
  <optional>
@@ -1994,6 +2086,7 @@
1994
2086
  <value>compare</value>
1995
2087
  <value>contrast</value>
1996
2088
  <value>see</value>
2089
+ <value>seealso</value>
1997
2090
  </choice>
1998
2091
  </define>
1999
2092
  <define name="deprecates">
@@ -2416,6 +2509,16 @@
2416
2509
  <text/>
2417
2510
  </element>
2418
2511
  </optional>
2512
+ <optional>
2513
+ <element name="amendment">
2514
+ <text/>
2515
+ </element>
2516
+ </optional>
2517
+ <optional>
2518
+ <element name="corrigendum">
2519
+ <text/>
2520
+ </element>
2521
+ </optional>
2419
2522
  <optional>
2420
2523
  <element name="language">
2421
2524
  <text/>
@@ -45,6 +45,9 @@
45
45
  <ref name="horizontal"/>
46
46
  </optional>
47
47
  <ref name="editorialgroup"/>
48
+ <optional>
49
+ <ref name="approvalgroup"/>
50
+ </optional>
48
51
  <zeroOrMore>
49
52
  <ref name="ics"/>
50
53
  </zeroOrMore>
@@ -249,6 +252,7 @@
249
252
  <value>warning</value>
250
253
  <value>important</value>
251
254
  <value>safety precautions</value>
255
+ <value>editorial</value>
252
256
  </choice>
253
257
  </define>
254
258
  <define name="preface">
@@ -308,18 +312,7 @@
308
312
  </define>
309
313
  <define name="editorialgroup">
310
314
  <element name="editorialgroup">
311
- <oneOrMore>
312
- <ref name="technical-committee"/>
313
- </oneOrMore>
314
- <zeroOrMore>
315
- <ref name="subcommittee"/>
316
- </zeroOrMore>
317
- <zeroOrMore>
318
- <ref name="workgroup"/>
319
- </zeroOrMore>
320
- <optional>
321
- <ref name="secretariat"/>
322
- </optional>
315
+ <ref name="ISOProjectGroup"/>
323
316
  </element>
324
317
  </define>
325
318
  <define name="Content-Section">
@@ -367,6 +360,33 @@
367
360
  </define>
368
361
  </include>
369
362
  <!-- end overrides -->
363
+ <define name="ISOProjectGroup">
364
+ <zeroOrMore>
365
+ <ref name="agency"/>
366
+ </zeroOrMore>
367
+ <oneOrMore>
368
+ <ref name="technical-committee"/>
369
+ </oneOrMore>
370
+ <zeroOrMore>
371
+ <ref name="subcommittee"/>
372
+ </zeroOrMore>
373
+ <zeroOrMore>
374
+ <ref name="workgroup"/>
375
+ </zeroOrMore>
376
+ <optional>
377
+ <ref name="secretariat"/>
378
+ </optional>
379
+ </define>
380
+ <define name="approvalgroup">
381
+ <element name="approvalgroup">
382
+ <ref name="ISOProjectGroup"/>
383
+ </element>
384
+ </define>
385
+ <define name="agency">
386
+ <element name="agency">
387
+ <text/>
388
+ </element>
389
+ </define>
370
390
  <!--
371
391
  We display the Normative References between scope and terms; but to keep the
372
392
  grammar simple, we keep the references together
@@ -4,7 +4,7 @@ module RelatonBsi
4
4
  british-standard draft-for-development published-document privately-subscribed-standard
5
5
  publicly-available-specification flex-standard international-standard technical-specification
6
6
  technical-report guide international-workshop-agreement industry-technical-agreement
7
- standard european-workshop-agreement
7
+ standard european-workshop-agreement fast-track-standard
8
8
  ].freeze
9
9
 
10
10
  SUBDOCTYPES = %w[specification method-of-test method-of-specifying vocabulary code-of-practice].freeze
@@ -35,7 +35,7 @@ module RelatonBsi
35
35
  def get(code, year = nil, opts = {})
36
36
  # y = code.split(":")[1]
37
37
  year ||= code_parts(code)[:year]
38
- ret = bib_get1(code, year, opts)
38
+ ret = bib_get(code, year, opts)
39
39
  return nil if ret.nil?
40
40
 
41
41
  ret = ret.to_most_recent_reference unless year || opts[:keep_year]
@@ -43,10 +43,27 @@ module RelatonBsi
43
43
  ret
44
44
  end
45
45
 
46
+ #
47
+ # Destruct code to its parts.
48
+ #
49
+ # @param [String] code document identifier
50
+ #
51
+ # @return [MatchData] parts of the code
52
+ #
53
+ def code_parts(code)
54
+ %r{
55
+ ^(?:BSI\s)?(?<code>(?:[A-Z]+\s)*[^:\s+]+)
56
+ (?::(?<year>\d{4}))?
57
+ (?:\+(?<a>[^:\s]+)(?::(?<y>\d{4}))?)?
58
+ (?:\s(?<rest>.+))?
59
+ }x.match code
60
+ end
61
+
46
62
  private
47
63
 
48
64
  def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
49
- id = year ? "#{code}:#{year}" : code
65
+ y = code_parts(code)[:year]
66
+ id = year && !y ? "#{code}:#{year}" : code
50
67
  warn "[relaton-bsi] WARNING: no match found online for #{id}. "\
51
68
  "The code must be exactly like it is on the standards website."
52
69
  unless missed_years.empty?
@@ -65,29 +82,19 @@ module RelatonBsi
65
82
  nil
66
83
  end
67
84
 
68
- def search_filter(code) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
69
- # %r{^(?:BSI\s)?(?<code1>[^:]+)} =~ code
70
- # %r{^(?<code1>[^:]+)} =~ code.sub(/^BSI\s/, "")
71
- cp1 = code_parts code
85
+ #
86
+ # Search for a BSI standard.
87
+ #
88
+ # @param [String] code the BSI standard Code to look up
89
+ #
90
+ # @return [RelatonBsi::HitCollection] a collection of hits
91
+ #
92
+ def search_filter(code)
93
+ cp = code_parts code
72
94
  warn "[relaton-bsi] (\"#{code}\") fetching..."
73
- return [] unless cp1
74
-
75
- result = search(code)
76
- result.select do |i|
77
- # %r{^(?<code2>[^:]+)} =~ i.hit[:code]
78
- cp2 = code_parts i.hit[:code]
79
- cp2[:code] == cp1[:code] && (!cp1[:a] || cp2[:a] == cp1[:a]) &&
80
- (!cp1[:y] || cp2[:y] == cp1[:y])
81
- end
82
- end
95
+ return [] unless cp
83
96
 
84
- def code_parts(code)
85
- %r{
86
- ^(?:BSI\s)?(?<code>[^:]+)
87
- (?::(?<year>\d{4}))?
88
- (?:\+(?<a>[^:]+):)?
89
- (?::(?<y>\d{4}))?
90
- }x.match code
97
+ search(code).filter_hits!(cp)
91
98
  end
92
99
 
93
100
  # Sort through the results from Isobib, fetching them three at a time,
@@ -96,10 +103,10 @@ module RelatonBsi
96
103
  # Only expects the first page of results to be populated.
97
104
  # Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
98
105
  # If no match, returns any years which caused mismatch, for error reporting
99
- def isobib_results_filter(result, year)
106
+ def results_filter(result, year)
100
107
  missed_years = []
101
108
  result.each do |r|
102
- /:(?<pyear>\d{4})/ =~ r.hit[:code]
109
+ pyear = code_parts(r.hit[:code])[:year]
103
110
  if !year || year == pyear
104
111
  ret = r.fetch
105
112
  return { ret: ret } if ret
@@ -110,9 +117,9 @@ module RelatonBsi
110
117
  { years: missed_years }
111
118
  end
112
119
 
113
- def bib_get1(code, year, _opts)
120
+ def bib_get(code, year, _opts)
114
121
  result = search_filter(code) || return
115
- ret = isobib_results_filter(result, year)
122
+ ret = results_filter(result, year)
116
123
  if ret[:ret]
117
124
  warn "[relaton-bsi] (\"#{code}\") found #{ret[:ret].docidentifier.first&.id}"
118
125
  ret[:ret]
@@ -8,8 +8,12 @@ module RelatonBsi
8
8
  class HitCollection < RelatonBib::HitCollection
9
9
  DOMAIN = "https://shop.bsigroup.com"
10
10
 
11
- # @param ref [String]
12
- # @param year [String]
11
+ #
12
+ # Initialize a new HitCollection.
13
+ #
14
+ # @param ref [String] reference
15
+ # @param year [String] year
16
+ #
13
17
  def initialize(ref, year = nil)
14
18
  super ref, year
15
19
  config = Algolia::Search::Config.new(
@@ -19,19 +23,40 @@ module RelatonBsi
19
23
  client = Algolia::Search::Client.new config, logger: ::Logger.new($stderr)
20
24
  index = client.init_index "shopify_products"
21
25
  resp = index.search text # , facetFilters: "product_type:standard"
22
- @array = hits resp[:hits]
26
+ @array = create_hits resp[:hits]
27
+ end
28
+
29
+ #
30
+ # Filter the search results for a BSI standard.
31
+ #
32
+ # @param [MatchData] code_parts parts of document identifier
33
+ #
34
+ # @return [self] filtered search results
35
+ #
36
+ def filter_hits!(code_parts)
37
+ hits = filter code_parts
38
+ hits = filter code_parts, skip_rest: true if hits.empty?
39
+ hits = filter code_parts, drop_amd: true if hits.empty?
40
+ @array = hits
41
+ self
23
42
  end
24
43
 
25
44
  private
26
45
 
27
- # @param hits [Array<Hash>]
28
- # @return [Array<RelatonBsi::Hit>]
29
- def hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
46
+ #
47
+ # Create hits from search results.
48
+ #
49
+ # @param hits [Array<Hash>] search results
50
+ #
51
+ # @return [Array<RelatonBsi::Hit>] hits
52
+ #
53
+ def create_hits(hits) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
30
54
  hits.each_with_object([]) do |h, obj|
31
55
  next unless h[:meta][:global][:publishedDate]
32
56
 
33
57
  code = h[:meta][:global][:primaryDesignator]
34
- .sub(/\s(?:LOOSELEAF|\(A5 LAMINATED\)|-\sTC$)/, "")
58
+ code = code.is_a?(Array) ? code.first : code
59
+ code.sub!(/\s?(?:LOOSELEAF|\(A5 LAMINATED\)|-\s?TC$)/, "")
35
60
  obj << Hit.new(
36
61
  {
37
62
  code: code,
@@ -46,5 +71,24 @@ module RelatonBsi
46
71
  )
47
72
  end.sort_by { |h| h.hit[:date] }.reverse
48
73
  end
74
+
75
+ #
76
+ # Select hits that match the document identifier.
77
+ #
78
+ # @param [MatchData] code_parts parts of document identifier
79
+ # @param [Boolean] drop_amd drop amendments and corrigendums
80
+ # @param [Boolean] skip_rest skip rest suffix of document identifier
81
+ #
82
+ def filter(code_parts, drop_amd: false, skip_rest: false) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
83
+ @array.select do |i|
84
+ code = drop_amd ? i.hit[:code].sub(/\+[AC]\d+.*$/, "") : i.hit[:code]
85
+ cp = BsiBibliography.code_parts code
86
+ match = cp[:code] == code_parts[:code] && cp[:a] == code_parts[:a] &&
87
+ (!code_parts[:y] || cp[:y] == code_parts[:y]) &&
88
+ (skip_rest || cp[:rest] == code_parts[:rest])
89
+ i.hit[:code] = code if drop_amd && match
90
+ match
91
+ end
92
+ end
49
93
  end
50
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonBsi
4
- VERSION = "1.11.0"
4
+ VERSION = "1.13.0"
5
5
  end
data/relaton_bsi.gemspec CHANGED
@@ -36,9 +36,9 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "vcr", "~> 5.0.0"
37
37
  spec.add_development_dependency "webmock"
38
38
 
39
- spec.add_dependency "algolia", "~> 2.1.1"
39
+ spec.add_dependency "algolia", "~> 2.2.0"
40
40
  spec.add_dependency "graphql", "1.13.6"
41
41
  spec.add_dependency "graphql-client", "~> 0.16.0"
42
42
  # spec.add_dependency "mechanize", "~> 2.8.0"
43
- spec.add_dependency "relaton-iso-bib", "~> 1.11.0"
43
+ spec.add_dependency "relaton-iso-bib", "~> 1.13.0"
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.13.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: 2022-04-10 00:00:00.000000000 Z
11
+ date: 2022-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 2.1.1
103
+ version: 2.2.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 2.1.1
110
+ version: 2.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: graphql
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.11.0
145
+ version: 1.13.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.11.0
152
+ version: 1.13.0
153
153
  description: 'RelatonBsi: retrieve BSI Standards for bibliographic use using the BibliographicItem
154
154
  model'
155
155
  email: