relaton-iec 1.2.0 → 1.6.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +2 -0
- data/.github/workflows/ubuntu.yml +1 -0
- data/.rubocop.yml +2 -2
- data/README.adoc +3 -3
- data/grammars/iec.rng +7 -0
- data/grammars/isodoc.rng +136 -21
- data/grammars/isostandard.rng +8 -1
- data/lib/relaton_iec/hit_collection.rb +29 -9
- data/lib/relaton_iec/iec_bibliography.rb +58 -49
- data/lib/relaton_iec/scrapper.rb +50 -16
- data/lib/relaton_iec/version.rb +1 -1
- data/relaton_iec.gemspec +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99612dcda07b9d860e087ecc3990a275b165539e2eefc83d4e5486feeb94ca4b
|
4
|
+
data.tar.gz: b15b0d2aa3860580697eb9ec009e68e96715be3e0debd9dc286b5527a250af02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15403a2fac73cfede74532468718a1c3a704d26b14cc54f2eabb7ea9f3451079003f62d4d22498809480c4ff64d84f6ab3e82689617dac3a082f348323abb0b7
|
7
|
+
data.tar.gz: 8ea1575201a593e580b39bcfe6205dd81f832116c967b88ec6608537b18e94410fab417eb9d1d2def971e996e7f35d16c43f53fe4641f7be2b0fb9b722a02fa2
|
data/.github/workflows/macos.yml
CHANGED
@@ -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: |
|
data/.rubocop.yml
CHANGED
data/README.adoc
CHANGED
@@ -18,7 +18,7 @@ Add this line to your application's Gemfile:
|
|
18
18
|
|
19
19
|
[source,ruby]
|
20
20
|
----
|
21
|
-
gem '
|
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
|
30
|
+
$ gem install relaton-iec
|
31
31
|
|
32
32
|
== Usage
|
33
33
|
|
34
|
-
Refer to https://github.com/
|
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
|
|
data/grammars/iec.rng
CHANGED
@@ -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"/>
|
data/grammars/isodoc.rng
CHANGED
@@ -43,7 +43,9 @@
|
|
43
43
|
<define name="xref">
|
44
44
|
<element name="xref">
|
45
45
|
<attribute name="target">
|
46
|
-
<data type="
|
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="
|
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
|
-
<
|
1050
|
-
<
|
1051
|
-
<
|
1052
|
-
|
1053
|
-
|
1054
|
-
<
|
1055
|
-
|
1056
|
-
|
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>
|
data/grammars/isostandard.rng
CHANGED
@@ -253,7 +253,7 @@
|
|
253
253
|
<define name="preface">
|
254
254
|
<element name="preface">
|
255
255
|
<optional>
|
256
|
-
<ref name="
|
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)
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
url
|
27
|
-
|
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
|
-
|
53
|
-
"
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
59
|
-
"use \"#{code} (all parts)\".\nIf the document is
|
60
|
-
"use its document type abbreviation (TS, TR, PAS,
|
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
|
-
|
66
|
-
|
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
|
-
|
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(<<~"
|
87
|
-
<bibitem>
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
</bibitem>
|
115
|
-
|
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
|
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
|
124
|
-
|
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
|
139
|
+
return { ret: r } if year.to_i == d.on(:year)
|
132
140
|
|
133
|
-
missed_years << d.on
|
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
|
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])
|
data/lib/relaton_iec/scrapper.rb
CHANGED
@@ -29,21 +29,21 @@ module RelatonIec
|
|
29
29
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
30
30
|
|
31
31
|
# Parse page.
|
32
|
-
# @param
|
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:
|
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=
|
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 }],
|
data/lib/relaton_iec/version.rb
CHANGED
data/relaton_iec.gemspec
CHANGED
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.
|
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-
|
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.
|
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.
|
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:
|
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'
|