relaton-iec 1.2.0 → 1.6.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d768dc96618e92bae39c2b4f01ad50d424a7a752931010cacff336f8084646a5
4
- data.tar.gz: e1049c6796a9ac144c1dff53df3a30b97db9c68638be4325af5fe1bd3d8eac0e
3
+ metadata.gz: 99612dcda07b9d860e087ecc3990a275b165539e2eefc83d4e5486feeb94ca4b
4
+ data.tar.gz: b15b0d2aa3860580697eb9ec009e68e96715be3e0debd9dc286b5527a250af02
5
5
  SHA512:
6
- metadata.gz: 89c424ea4e70145b7f6373842b4e59bbbddbf74c16e99a09e33d001dc92345e42918d77910e7051a01e37c50be9aa8495b8cc39daf8840626238ab162ff68c87
7
- data.tar.gz: 43852861bd4b77052be882668d1363a6eca939c10c15faf882048ddd93ba81d0f5e439f9176fdaa9e9a541f22cfae2b51e017a50b8f46d036f6622daa380d5b1
6
+ metadata.gz: 15403a2fac73cfede74532468718a1c3a704d26b14cc54f2eabb7ea9f3451079003f62d4d22498809480c4ff64d84f6ab3e82689617dac3a082f348323abb0b7
7
+ data.tar.gz: 8ea1575201a593e580b39bcfe6205dd81f832116c967b88ec6608537b18e94410fab417eb9d1d2def971e996e7f35d16c43f53fe4641f7be2b0fb9b722a02fa2
@@ -26,6 +26,8 @@ jobs:
26
26
  - name: Update gems
27
27
  run: |
28
28
  sudo gem install bundler --force
29
+ ruby -v | grep 2.5 && bundle config set build.debase --with-cflags="-Wno-error=implicit-function-declaration"
30
+ ruby -v | grep 2.5 && bundle config set build.ruby-debug-ide --with-cflags="-Wno-error=implicit-function-declaration"
29
31
  bundle install --jobs 4 --retry 3
30
32
  - name: Run specs
31
33
  run: |
@@ -29,4 +29,5 @@ jobs:
29
29
  bundle install --jobs 4 --retry 3
30
30
  - name: Run specs
31
31
  run: |
32
+ unset JAVA_TOOL_OPTIONS
32
33
  bundle exec rake
@@ -5,6 +5,6 @@
5
5
  inherit_from:
6
6
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
7
7
  AllCops:
8
- TargetRubyVersion: 2.3
8
+ TargetRubyVersion: 2.4
9
9
  Rails:
10
- Enabled: true
10
+ Enabled: false
@@ -18,7 +18,7 @@ Add this line to your application's Gemfile:
18
18
 
19
19
  [source,ruby]
20
20
  ----
21
- gem 'relaton_iec'
21
+ gem 'relaton-iec'
22
22
  ----
23
23
 
24
24
  And then execute:
@@ -27,11 +27,11 @@ And then execute:
27
27
 
28
28
  Or install it yourself as:
29
29
 
30
- $ gem install relaton_iec
30
+ $ gem install relaton-iec
31
31
 
32
32
  == Usage
33
33
 
34
- Refer to https://github.com/metanorma/relaton-iso/blob/master/README.adoc: the usage interface is identical.
34
+ Refer to https://github.com/relaton/relaton-iso/blob/master/README.adoc the usage interface is identical.
35
35
 
36
36
  == Development
37
37
 
@@ -23,6 +23,13 @@
23
23
  -->
24
24
  <define name="iec-standard">
25
25
  <element name="iec-standard">
26
+ <attribute name="version"/>
27
+ <attribute name="type">
28
+ <choice>
29
+ <value>semantic</value>
30
+ <value>presentation</value>
31
+ </choice>
32
+ </attribute>
26
33
  <ref name="bibdata"/>
27
34
  <zeroOrMore>
28
35
  <ref name="termdocsource"/>
@@ -43,7 +43,9 @@
43
43
  <define name="xref">
44
44
  <element name="xref">
45
45
  <attribute name="target">
46
- <data type="IDREF"/>
46
+ <data type="string">
47
+ <param name="pattern">\i\c*|\c+#\c+</param>
48
+ </data>
47
49
  </attribute>
48
50
  <optional>
49
51
  <attribute name="type">
@@ -61,6 +63,11 @@
61
63
  </choice>
62
64
  </attribute>
63
65
  </optional>
66
+ <optional>
67
+ <attribute name="droploc">
68
+ <data type="boolean"/>
69
+ </attribute>
70
+ </optional>
64
71
  <text/>
65
72
  </element>
66
73
  </define>
@@ -578,6 +585,8 @@
578
585
  <ref name="ol"/>
579
586
  <ref name="dl"/>
580
587
  <ref name="formula"/>
588
+ <ref name="quote"/>
589
+ <ref name="sourcecode"/>
581
590
  </choice>
582
591
  </oneOrMore>
583
592
  </element>
@@ -661,6 +670,16 @@
661
670
  </choice>
662
671
  </attribute>
663
672
  </optional>
673
+ <optional>
674
+ <attribute name="valign">
675
+ <choice>
676
+ <value>top</value>
677
+ <value>middle</value>
678
+ <value>bottom</value>
679
+ <value>baseline</value>
680
+ </choice>
681
+ </attribute>
682
+ </optional>
664
683
  <choice>
665
684
  <zeroOrMore>
666
685
  <choice>
@@ -697,6 +716,16 @@
697
716
  </choice>
698
717
  </attribute>
699
718
  </optional>
719
+ <optional>
720
+ <attribute name="valign">
721
+ <choice>
722
+ <value>top</value>
723
+ <value>middle</value>
724
+ <value>bottom</value>
725
+ <value>baseline</value>
726
+ </choice>
727
+ </attribute>
728
+ </optional>
700
729
  <choice>
701
730
  <zeroOrMore>
702
731
  <choice>
@@ -834,6 +863,13 @@
834
863
  </define>
835
864
  <define name="standard-document">
836
865
  <element name="standard-document">
866
+ <attribute name="version"/>
867
+ <attribute name="type">
868
+ <choice>
869
+ <value>semantic</value>
870
+ <value>presentation</value>
871
+ </choice>
872
+ </attribute>
837
873
  <ref name="bibdata"/>
838
874
  <optional>
839
875
  <ref name="boilerplate"/>
@@ -855,7 +891,7 @@
855
891
  <oneOrMore>
856
892
  <choice>
857
893
  <ref name="content"/>
858
- <ref name="preface_abstract"/>
894
+ <ref name="abstract"/>
859
895
  <ref name="foreword"/>
860
896
  <ref name="introduction"/>
861
897
  <ref name="acknowledgements"/>
@@ -922,6 +958,9 @@
922
958
  <optional>
923
959
  <attribute name="script"/>
924
960
  </optional>
961
+ <optional>
962
+ <attribute name="type"/>
963
+ </optional>
925
964
  <optional>
926
965
  <attribute name="obligation">
927
966
  <choice>
@@ -961,9 +1000,6 @@
961
1000
  </define>
962
1001
  <define name="content-subsection">
963
1002
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
1003
  <ref name="Content-Section"/>
968
1004
  </element>
969
1005
  </define>
@@ -992,6 +1028,9 @@
992
1028
  </choice>
993
1029
  </attribute>
994
1030
  </optional>
1031
+ <optional>
1032
+ <attribute name="type"/>
1033
+ </optional>
995
1034
  <optional>
996
1035
  <ref name="section-title"/>
997
1036
  </optional>
@@ -1011,9 +1050,6 @@
1011
1050
  </define>
1012
1051
  <define name="clause">
1013
1052
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1053
  <ref name="Clause-Section"/>
1018
1054
  </element>
1019
1055
  </define>
@@ -1042,18 +1078,24 @@
1042
1078
  </choice>
1043
1079
  </attribute>
1044
1080
  </optional>
1081
+ <optional>
1082
+ <attribute name="type"/>
1083
+ </optional>
1045
1084
  <optional>
1046
1085
  <ref name="section-title"/>
1047
1086
  </optional>
1048
1087
  <group>
1049
- <group>
1050
- <zeroOrMore>
1051
- <ref name="BasicBlock"/>
1052
- </zeroOrMore>
1053
- <zeroOrMore>
1054
- <ref name="note"/>
1055
- </zeroOrMore>
1056
- </group>
1088
+ <choice>
1089
+ <group>
1090
+ <zeroOrMore>
1091
+ <ref name="BasicBlock"/>
1092
+ </zeroOrMore>
1093
+ <zeroOrMore>
1094
+ <ref name="note"/>
1095
+ </zeroOrMore>
1096
+ </group>
1097
+ <ref name="amend"/>
1098
+ </choice>
1057
1099
  <zeroOrMore>
1058
1100
  <choice>
1059
1101
  <ref name="clause-subsection"/>
@@ -1180,6 +1222,9 @@
1180
1222
  <optional>
1181
1223
  <attribute name="script"/>
1182
1224
  </optional>
1225
+ <optional>
1226
+ <attribute name="type"/>
1227
+ </optional>
1183
1228
  <optional>
1184
1229
  <attribute name="obligation">
1185
1230
  <choice>
@@ -1447,11 +1492,6 @@
1447
1492
  </optional>
1448
1493
  </element>
1449
1494
  </define>
1450
- <define name="preface_abstract">
1451
- <element name="abstract">
1452
- <ref name="Basic-Section"/>
1453
- </element>
1454
- </define>
1455
1495
  <define name="term-clause">
1456
1496
  <element name="clause">
1457
1497
  <optional>
@@ -1501,4 +1541,79 @@
1501
1541
  <ref name="CitationType"/>
1502
1542
  </element>
1503
1543
  </define>
1544
+ <define name="amend">
1545
+ <element name="amend">
1546
+ <optional>
1547
+ <attribute name="id">
1548
+ <data type="ID"/>
1549
+ </attribute>
1550
+ </optional>
1551
+ <attribute name="change">
1552
+ <choice>
1553
+ <value>add</value>
1554
+ <value>modify</value>
1555
+ <value>delete</value>
1556
+ </choice>
1557
+ </attribute>
1558
+ <optional>
1559
+ <attribute name="path"/>
1560
+ </optional>
1561
+ <optional>
1562
+ <attribute name="path_end"/>
1563
+ </optional>
1564
+ <optional>
1565
+ <attribute name="title"/>
1566
+ </optional>
1567
+ <optional>
1568
+ <element name="location">
1569
+ <zeroOrMore>
1570
+ <ref name="locality"/>
1571
+ </zeroOrMore>
1572
+ </element>
1573
+ </optional>
1574
+ <zeroOrMore>
1575
+ <ref name="autonumber"/>
1576
+ </zeroOrMore>
1577
+ <optional>
1578
+ <element name="description">
1579
+ <zeroOrMore>
1580
+ <ref name="BasicBlock"/>
1581
+ </zeroOrMore>
1582
+ </element>
1583
+ </optional>
1584
+ <optional>
1585
+ <element name="newcontent">
1586
+ <zeroOrMore>
1587
+ <ref name="BasicBlock"/>
1588
+ </zeroOrMore>
1589
+ </element>
1590
+ </optional>
1591
+ <optional>
1592
+ <element name="description">
1593
+ <zeroOrMore>
1594
+ <ref name="BasicBlock"/>
1595
+ </zeroOrMore>
1596
+ </element>
1597
+ </optional>
1598
+ </element>
1599
+ </define>
1600
+ <define name="autonumber">
1601
+ <element name="autonumber">
1602
+ <attribute name="type">
1603
+ <choice>
1604
+ <value>requirement</value>
1605
+ <value>recommendation</value>
1606
+ <value>permission</value>
1607
+ <value>table</value>
1608
+ <value>figure</value>
1609
+ <value>admonition</value>
1610
+ <value>formula</value>
1611
+ <value>sourcecode</value>
1612
+ <value>example</value>
1613
+ <value>note</value>
1614
+ </choice>
1615
+ </attribute>
1616
+ <text/>
1617
+ </element>
1618
+ </define>
1504
1619
  </grammar>
@@ -253,7 +253,7 @@
253
253
  <define name="preface">
254
254
  <element name="preface">
255
255
  <optional>
256
- <ref name="preface_abstract"/>
256
+ <ref name="abstract"/>
257
257
  </optional>
258
258
  <ref name="foreword"/>
259
259
  <optional>
@@ -405,6 +405,13 @@
405
405
  -->
406
406
  <define name="iso-standard">
407
407
  <element name="iso-standard">
408
+ <attribute name="version"/>
409
+ <attribute name="type">
410
+ <choice>
411
+ <value>semantic</value>
412
+ <value>presentation</value>
413
+ </choice>
414
+ </attribute>
408
415
  <ref name="bibdata"/>
409
416
  <zeroOrMore>
410
417
  <ref name="termdocsource"/>
@@ -10,22 +10,42 @@ module RelatonIec
10
10
 
11
11
  # @param ref_nbr [String]
12
12
  # @param year [String]
13
- def initialize(ref_nbr, year = nil) #(text, hit_pages = nil)
13
+ def initialize(ref_nbr, year = nil)
14
14
  super
15
+ @array = hits ref_nbr, year
16
+ end
17
+
18
+ private
19
+
20
+ def hits(ref, year)
15
21
  from, to = nil
16
22
  if year
17
23
  from = Date.strptime year, "%Y"
18
24
  to = from.next_year.prev_day
19
25
  end
20
- url = "#{DOMAIN}/searchkey&RefNbr=#{ref_nbr}&From=#{from}&To=#{to}&start=1"
21
- doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
22
- @array = doc.css("ul.search-results > li").map do |h|
23
- link = h.at('a[@href!="#"]')
24
- code = link.text.tr [194, 160].pack("c*").force_encoding("UTF-8"), ""
25
- title = h.xpath("text()").text.gsub(/[\r\n]/, "")
26
- url = DOMAIN + link[:href]
27
- Hit.new({ code: code, title: title, url: url }, self)
26
+ get_results ref, from, to
27
+ end
28
+
29
+ def get_results(ref, from,to)
30
+ [nil, "trf", "wr"].reduce([]) do |m, t|
31
+ url = "#{DOMAIN}/searchkey"
32
+ url += "&type=#{t}" if t
33
+ url += "&RefNbr=#{ref}&From=#{from}&To=#{to}&start=1"
34
+ m + results(Addressable::URI.parse(url).normalize)
28
35
  end
29
36
  end
37
+
38
+ def results(uri)
39
+ Nokogiri::HTML(OpenURI.open_uri(uri)).css(
40
+ "//body/li", "ul.search-results > li", "ul.morethesame > li"
41
+ ).map { |h| make_hit h }
42
+ end
43
+
44
+ def make_hit(hit)
45
+ link = hit.at('a[@href!="#"]')
46
+ code = link.text.tr [194, 160].pack("c*").force_encoding("UTF-8"), ""
47
+ title = hit.xpath("text()").text.gsub(/[\r\n]/, "")
48
+ Hit.new({ code: code, title: title, url: DOMAIN + link[:href] }, self)
49
+ end
30
50
  end
31
51
  end
@@ -22,7 +22,7 @@ module RelatonIec
22
22
  # @param opts [Hash] options; restricted to :all_parts if all-parts
23
23
  # reference is required
24
24
  # @return [String] Relaton XML serialisation of reference
25
- def get(code, year = nil, opts = {})
25
+ def get(code, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
26
26
  if year.nil?
27
27
  /^(?<code1>[^:]+):(?<year1>[^:]+)/ =~ code
28
28
  unless code1.nil?
@@ -45,27 +45,33 @@ module RelatonIec
45
45
 
46
46
  private
47
47
 
48
- def fetch_ref_err(code, year, missed_years)
48
+ def fetch_ref_err(code, year, missed_years) # rubocop:disable Metrics/MethodLength
49
49
  id = year ? "#{code}:#{year}" : code
50
50
  warn "[relaton-iec] WARNING: no match found online for #{id}. "\
51
51
  "The code must be exactly like it is on the standards website."
52
- warn "[relaton-iec] (There was no match for #{year}, though there were matches "\
53
- "found for #{missed_years.join(', ')}.)" unless missed_years.empty?
54
- if /\d-\d/ =~ code
55
- warn "[relaton-iec] The provided document part may not exist, or the document "\
56
- "may no longer be published in parts."
52
+ unless missed_years.empty?
53
+ warn "[relaton-iec] (There was no match for #{year}, though there "\
54
+ "were matches found for #{missed_years.join(', ')}.)"
55
+ end
56
+ if /\d-\d/.match? code
57
+ warn "[relaton-iec] The provided document part may not exist, or "\
58
+ "the document may no longer be published in parts."
57
59
  else
58
- warn "[relaton-iec] If you wanted to cite all document parts for the reference, "\
59
- "use \"#{code} (all parts)\".\nIf the document is not a standard, "\
60
- "use its document type abbreviation (TS, TR, PAS, Guide)."
60
+ warn "[relaton-iec] If you wanted to cite all document parts for "\
61
+ "the reference, use \"#{code} (all parts)\".\nIf the document is "\
62
+ "not a standard, use its document type abbreviation (TS, TR, PAS, "\
63
+ "Guide)."
61
64
  end
62
65
  nil
63
66
  end
64
67
 
65
- def fetch_pages(s, n)
66
- workers = RelatonBib::WorkersPool.new n
68
+ # @param hits [Array<RelatonIec::Hit>]
69
+ # @param threads [Integer]
70
+ # @return [Array<RelatonIec::Hit>]
71
+ def fetch_pages(hits, threads)
72
+ workers = RelatonBib::WorkersPool.new threads
67
73
  workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
68
- s.each_with_index { |hit, i| workers << { i: i, hit: hit } }
74
+ hits.each_with_index { |hit, i| workers << { i: i, hit: hit } }
69
75
  workers.end
70
76
  workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
71
77
  end
@@ -83,54 +89,56 @@ module RelatonIec
83
89
  end
84
90
 
85
91
  def iev(code = "IEC 60050")
86
- RelatonIsoBib::XMLParser.from_xml(<<~"END")
87
- <bibitem>
88
- <fetched>#{Date.today}</fetched>
89
- <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
90
- <link type="src">http://www.electropedia.org</link>
91
- <docidentifier>#{code}:2011</docidentifier>
92
- <date type="published"><on>2011</on></date>
93
- <contributor>
94
- <role type="publisher"/>
95
- <organization>
96
- <name>International Electrotechnical Commission</name>
97
- <abbreviation>IEC</abbreviation>
98
- <uri>www.iec.ch</uri>
99
- </organization>
100
- </contributor>
101
- <language>en</language> <language>fr</language>
102
- <script>Latn</script>
103
- <status> <stage>60</stage> </status>
104
- <copyright>
105
- <from>2018</from>
106
- <owner>
107
- <organization>
108
- <name>International Electrotechnical Commission</name>
109
- <abbreviation>IEC</abbreviation>
110
- <uri>www.iec.ch</uri>
111
- </organization>
112
- </owner>
113
- </copyright>
114
- </bibitem>
115
- END
92
+ RelatonIsoBib::XMLParser.from_xml(<<~"XML")
93
+ <bibitem>
94
+ <fetched>#{Date.today}</fetched>
95
+ <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
96
+ <link type="src">http://www.electropedia.org</link>
97
+ <docidentifier>#{code}:2011</docidentifier>
98
+ <date type="published"><on>2011</on></date>
99
+ <contributor>
100
+ <role type="publisher"/>
101
+ <organization>
102
+ <name>International Electrotechnical Commission</name>
103
+ <abbreviation>IEC</abbreviation>
104
+ <uri>www.iec.ch</uri>
105
+ </organization>
106
+ </contributor>
107
+ <language>en</language> <language>fr</language>
108
+ <script>Latn</script>
109
+ <status> <stage>60</stage> </status>
110
+ <copyright>
111
+ <from>2018</from>
112
+ <owner>
113
+ <organization>
114
+ <name>International Electrotechnical Commission</name>
115
+ <abbreviation>IEC</abbreviation>
116
+ <uri>www.iec.ch</uri>
117
+ </organization>
118
+ </owner>
119
+ </copyright>
120
+ </bibitem>
121
+ XML
116
122
  end
117
123
 
118
124
  # Sort through the results from Isobib, fetching them three at a time,
119
125
  # and return the first result that matches the code,
120
- # matches the year (if provided), and which # has a title (amendments do not).
126
+ # matches the year (if provided), and which
127
+ # has a title (amendments do not).
121
128
  # Only expects the first page of results to be populated.
122
129
  # Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
123
- # If no match, returns any years which caused mismatch, for error reporting
124
- def isobib_results_filter(result, year)
130
+ # If no match, returns any years which caused mismatch, for error
131
+ # reporting
132
+ def isobib_results_filter(result, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
125
133
  missed_years = []
126
134
  result.each_slice(3) do |s| # ISO website only allows 3 connections
127
135
  fetch_pages(s, 3).each_with_index do |r, _i|
128
136
  return { ret: r } if !year
129
137
 
130
138
  r.date.select { |d| d.type == "published" }.each do |d|
131
- return { ret: r } if year.to_i == d.on.year
139
+ return { ret: r } if year.to_i == d.on(:year)
132
140
 
133
- missed_years << d.on.year
141
+ missed_years << d.on(:year)
134
142
  end
135
143
  end
136
144
  end
@@ -143,7 +151,8 @@ module RelatonIec
143
151
  result = isobib_search_filter(code) || return
144
152
  ret = isobib_results_filter(result, year)
145
153
  if ret[:ret]
146
- warn "[relaton-iec] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
154
+ warn "[relaton-iec] (\"#{code}\") found "\
155
+ "#{ret[:ret].docidentifier.first.id}"
147
156
  ret[:ret]
148
157
  else
149
158
  fetch_ref_err(code, year, ret[:years])
@@ -29,21 +29,21 @@ module RelatonIec
29
29
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
30
30
 
31
31
  # Parse page.
32
- # @param hit [Hash]
32
+ # @param hit_data [Hash]
33
33
  # @return [Hash]
34
34
  def parse_page(hit_data)
35
35
  doc = get_page hit_data[:url]
36
36
 
37
37
  # Fetch edition.
38
38
  edition = doc.at(
39
- "//th[contains(., 'Edition')]/following-sibling::td/span",
39
+ "//th[contains(., 'Edition')]/following-sibling::td/span"
40
40
  ).text
41
41
 
42
42
  status, relations = fetch_status_relations hit_data[:url]
43
43
 
44
44
  IecBibliographicItem.new(
45
45
  fetched: Date.today.to_s,
46
- docid: [RelatonBib::DocumentIdentifier.new(id: hit_data[:code], type: "IEC")],
46
+ docid: fetch_docid(hit_data),
47
47
  structuredidentifier: fetch_structuredidentifier(doc),
48
48
  edition: edition,
49
49
  language: ["en"],
@@ -59,13 +59,48 @@ module RelatonIec
59
59
  copyright: fetch_copyright(hit_data[:code], doc),
60
60
  link: fetch_link(doc, hit_data[:url]),
61
61
  relation: relations,
62
- place: ["Geneva"],
62
+ place: ["Geneva"]
63
63
  )
64
64
  end
65
65
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
66
66
 
67
67
  private
68
68
 
69
+ # @param hit [Hash]
70
+ # @return [Array<RelatonBib::DocumentIdentifier>]
71
+ def fetch_docid(hit)
72
+ rest = hit[:code].downcase.sub(%r{
73
+ (?<head>[^\s]+)\s
74
+ (?<type>is|ts|tr|pas|srd|guide|tec|wp)?(?(<type>)\s)
75
+ (?<pnum>[\d-]+)\s?
76
+ (?<_dd>:)?(?(<_dd>)(?<date>[\d-]+)\s?)
77
+ }x, "")
78
+ m = $~
79
+ deliv = /cmv|csv|exv|prv|rlv|ser/.match(hit[:code].downcase).to_s
80
+ urn = ["urn", "iec", "std", m[:head].split("/").join("-"), m[:pnum],
81
+ m[:date], m[:type], deliv, "en"]
82
+ urn += fetch_ajunct(rest)
83
+ [
84
+ RelatonBib::DocumentIdentifier.new(id: hit[:code], type: "IEC"),
85
+ RelatonBib::DocumentIdentifier.new(id: urn.join(":"), type: "URN"),
86
+ ]
87
+ end
88
+
89
+ # @param rest [String]
90
+ # @return [Array<String, nil>]
91
+ def fetch_ajunct(rest)
92
+ r = rest.sub(%r{
93
+ (?<_pl>\+)(?(<_pl>)(?<adjunct>amd)(?<adjnum>\d+)\s?)
94
+ (?<_d2>:)?(?(<_d2>)(?<adjdt>[\d-]+)\s?)
95
+ }x, "")
96
+ m = $~ || {}
97
+ return [] unless m[:adjunct]
98
+
99
+ plus = m[:adjunct] && "plus"
100
+ urn = [plus, m[:adjunct], m[:adjnum], m[:adjdt]]
101
+ urn + fetch_ajunct(r)
102
+ end
103
+
69
104
  # Fetch abstracts.
70
105
  # @param doc [Nokigiri::HTML::Document]
71
106
  # @return [Array<Array>]
@@ -111,12 +146,12 @@ module RelatonIec
111
146
  item_ref = doc.at("//span[@itemprop='productID']")
112
147
  unless item_ref
113
148
  return RelatonIsoBib::StructuredIdentifier.new(
114
- project_number: "?", part_number: "", prefix: nil, id: "?",
149
+ project_number: "?", part_number: "", prefix: nil, id: "?"
115
150
  )
116
151
  end
117
152
 
118
153
  m = item_ref.text.match(
119
- /(?<=\s)(?<project>\d+)-?(?<part>(?<=-)\d+|)-?(?<subpart>(?<=-)\d+|)/,
154
+ /(?<=\s)(?<project>\d+)-?(?<part>(?<=-)\d+|)-?(?<subpart>(?<=-)\d+|)/
120
155
  )
121
156
  RelatonIsoBib::StructuredIdentifier.new(
122
157
  project_number: m[:project],
@@ -124,7 +159,7 @@ module RelatonIec
124
159
  subpart_number: m[:subpart],
125
160
  prefix: nil,
126
161
  type: "IEC",
127
- id: item_ref.text,
162
+ id: item_ref.text
128
163
  )
129
164
  end
130
165
 
@@ -168,8 +203,8 @@ module RelatonIec
168
203
  # @return [Array<Hash>]
169
204
  # rubocop:disable Metrics/MethodLength
170
205
  def fetch_relations(doc)
171
- doc.xpath('//ROW[STATUS[.!="PREPARING"]][STATUS[.!="PUBLISHED"]]').
172
- map do |r|
206
+ doc.xpath('//ROW[STATUS[.!="PREPARING"]][STATUS[.!="PUBLISHED"]]')
207
+ .map do |r|
173
208
  r_type = r.at("STATUS").text.downcase
174
209
  type = case r_type
175
210
  # when 'published' then 'obsoletes' # Valid
@@ -178,7 +213,7 @@ module RelatonIec
178
213
  else r_type
179
214
  end
180
215
  fref = RelatonBib::FormattedRef.new(
181
- content: r.at("FULL_NAME").text, format: "text/plain",
216
+ content: r.at("FULL_NAME").text, format: "text/plain"
182
217
  )
183
218
  bibitem = IecBibliographicItem.new(formattedref: fref)
184
219
  { type: type, bibitem: bibitem }
@@ -188,8 +223,7 @@ module RelatonIec
188
223
  def fetch_status_relations(url)
189
224
  pubid = url.match(/\d+$/).to_s
190
225
  uri = URI DOMAIN + "/webstore/webstore.nsf/AjaxRequestXML?"\
191
- "Openagent&url=http://www.iec.ch/dyn/www/f?"\
192
- "p=103:390:::::P390_PUBLICATION_ID:" + pubid
226
+ "Openagent&url=" + pubid
193
227
  resp = Net::HTTP.get_response uri
194
228
  doc = Nokogiri::XML resp.body
195
229
  status = fetch_status doc
@@ -203,7 +237,7 @@ module RelatonIec
203
237
  # @return [String]
204
238
  def fetch_type(doc)
205
239
  doc.at(
206
- '//th[contains(., "Publication type")]/following-sibling::td/span',
240
+ '//th[contains(., "Publication type")]/following-sibling::td/span'
207
241
  ).text.downcase.tr " ", "-"
208
242
  end
209
243
 
@@ -249,7 +283,7 @@ module RelatonIec
249
283
  # @return [Array<Hash>]
250
284
  def fetch_ics(doc)
251
285
  doc.xpath(
252
- '//th[contains(text(), "ICS")]/following-sibling::td/a',
286
+ '//th[contains(text(), "ICS")]/following-sibling::td/a'
253
287
  ).map do |i|
254
288
  code = i.text.match(/[\d\.]+/).to_s.split "."
255
289
  { field: code[0], group: code[1], subgroup: code[2] }
@@ -281,8 +315,8 @@ module RelatonIec
281
315
  end
282
316
  from = code.match(/(?<=:)\d{4}/).to_s
283
317
  if from.empty?
284
- from = doc.xpath("//span[@itemprop='releaseDate']").text.
285
- match(/\d{4}/).to_s
318
+ from = doc.xpath("//span[@itemprop='releaseDate']").text
319
+ .match(/\d{4}/).to_s
286
320
  end
287
321
  [{
288
322
  owner: [{ name: name, abbreviation: abbreviation, url: url }],
@@ -1,3 +1,3 @@
1
1
  module RelatonIec
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.6.pre1".freeze
3
3
  end
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "webmock"
36
36
 
37
37
  spec.add_dependency "addressable"
38
- spec.add_dependency "relaton-iso-bib", "~> 1.2.0"
38
+ spec.add_dependency "relaton-iso-bib", "~> 1.6.pre"
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.6.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 1.2.0
173
+ version: 1.6.pre
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 1.2.0
180
+ version: 1.6.pre
181
181
  description: 'RelatonIec: retrieve IEC Standards for bibliographic use using the IecBibliographicItem
182
182
  model'
183
183
  email:
@@ -220,7 +220,7 @@ homepage: https://github.com/metanorma/relaton-iec
220
220
  licenses:
221
221
  - MIT
222
222
  metadata: {}
223
- post_install_message:
223
+ post_install_message:
224
224
  rdoc_options: []
225
225
  require_paths:
226
226
  - lib
@@ -231,12 +231,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
231
  version: 2.4.0
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - ">="
234
+ - - ">"
235
235
  - !ruby/object:Gem::Version
236
- version: '0'
236
+ version: 1.3.1
237
237
  requirements: []
238
238
  rubygems_version: 3.0.6
239
- signing_key:
239
+ signing_key:
240
240
  specification_version: 4
241
241
  summary: 'RelatonIec: retrieve IEC Standards for bibliographic use using the IecBibliographicItem
242
242
  model'