relaton-iec 1.6.0 → 1.7.0

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: ce61292fadf50fe832b8cd82340ff7978dd88ca647a77dfcb4b1024e663d1920
4
- data.tar.gz: 75c21f0d072251b25afa1fb79a5fd9d050f7346b27b1da509c3ef5010e2144a0
3
+ metadata.gz: affb3c4e8c5d26115be469d456d5b3de4f89f1184226b7a51b8dbabdd1cae937
4
+ data.tar.gz: cb850e8a8cbae05c66b629db7f2ee548debf0f1dfe3d03d6dc75e8c6e85900d2
5
5
  SHA512:
6
- metadata.gz: 476865eb91561a56dc9ef96c08aec6f3aafe9cda4f0dc444db0cf433fc36889d9604ca936f6ab66576408a6f0e54d7bf013feb089683d8f903ec508ba003c221
7
- data.tar.gz: e852f3cfb7db70dd61bb8729881e7d1d935add63a01f80583e166ae426d26a8765cbc4293e13251110206af10c61a923ef4033d97ffd258a17793acff08fd69d
6
+ metadata.gz: 107761f95543a8f188d45e5aa3ea676fe904a152d32d0ebdd92e1e66ac42e2164287ac0feef3906fbb596bd6807636c3f70938fe301a2b53f2ffaf34cf316b54
7
+ data.tar.gz: bcd04f967647bed2d2a4cebaff71cf5acf03ad1e388a81d44f150e9d1d4bbdbd9d16e3de222134d5806112453a3e0e4fd82aa3cc2f9ce1e55047b7f9439b9d4c
@@ -24,6 +24,14 @@
24
24
  <start>
25
25
  <ref name="standard-document"/>
26
26
  </start>
27
+ <define name="doctype">
28
+ <element name="doctype">
29
+ <optional>
30
+ <attribute name="abbreviation"/>
31
+ </optional>
32
+ <ref name="DocumentType"/>
33
+ </element>
34
+ </define>
27
35
  <define name="hyperlink">
28
36
  <element name="link">
29
37
  <attribute name="target">
@@ -141,6 +149,11 @@
141
149
  <data type="boolean"/>
142
150
  </attribute>
143
151
  </optional>
152
+ <optional>
153
+ <attribute name="key">
154
+ <data type="boolean"/>
155
+ </attribute>
156
+ </optional>
144
157
  <oneOrMore>
145
158
  <ref name="dt"/>
146
159
  <ref name="dd"/>
@@ -1164,49 +1177,7 @@
1164
1177
  </define>
1165
1178
  <define name="annex">
1166
1179
  <element name="annex">
1167
- <optional>
1168
- <attribute name="id">
1169
- <data type="ID"/>
1170
- </attribute>
1171
- </optional>
1172
- <optional>
1173
- <attribute name="language"/>
1174
- </optional>
1175
- <optional>
1176
- <attribute name="script"/>
1177
- </optional>
1178
- <optional>
1179
- <attribute name="inline-header">
1180
- <data type="boolean"/>
1181
- </attribute>
1182
- </optional>
1183
- <attribute name="obligation">
1184
- <choice>
1185
- <value>normative</value>
1186
- <value>informative</value>
1187
- </choice>
1188
- </attribute>
1189
- <optional>
1190
- <ref name="section-title"/>
1191
- </optional>
1192
- <group>
1193
- <group>
1194
- <zeroOrMore>
1195
- <ref name="BasicBlock"/>
1196
- </zeroOrMore>
1197
- <zeroOrMore>
1198
- <ref name="note"/>
1199
- </zeroOrMore>
1200
- </group>
1201
- <zeroOrMore>
1202
- <choice>
1203
- <ref name="annex-subsection"/>
1204
- <ref name="terms"/>
1205
- <ref name="definitions"/>
1206
- <ref name="references"/>
1207
- </choice>
1208
- </zeroOrMore>
1209
- </group>
1180
+ <ref name="Annex-Section"/>
1210
1181
  </element>
1211
1182
  </define>
1212
1183
  <define name="terms">
@@ -9,35 +9,52 @@ module RelatonIec
9
9
  DOMAIN = "https://webstore.iec.ch"
10
10
 
11
11
  # @param ref_nbr [String]
12
- # @param year [String]
13
- def initialize(ref_nbr, year = nil)
14
- super
15
- @array = hits ref_nbr, year
12
+ # @param year [String, nil]
13
+ # @param part [String, nil]
14
+ def initialize(ref_nbr, year = nil, part = nil)
15
+ super ref_nbr, year
16
+ @array = hits ref_nbr, year, part
16
17
  end
17
18
 
18
19
  private
19
20
 
20
- def hits(ref, year)
21
+ # @param ref [String]
22
+ # @param year [String, nil]
23
+ # @param part [String, nil]
24
+ # @return [Array<RelatonIec::Hit>]
25
+ def hits(ref, year, part)
21
26
  from, to = nil
22
27
  if year
23
28
  from = Date.strptime year, "%Y"
24
29
  to = from.next_year.prev_day
25
30
  end
26
- get_results ref, from, to
31
+ get_results ref, from, to, part
27
32
  end
28
33
 
29
- def get_results(ref, from,to)
34
+ # @param ref [String]
35
+ # @param from [Date, nil]
36
+ # @param to [Date, nil]
37
+ # @param part [String, nil]
38
+ # @return [Array<RelatonIec::Hit>]
39
+ def get_results(ref, from, to, part = nil)
40
+ code = part ? ref.sub(/(?<=-\d)\d+/, "*") : ref
30
41
  [nil, "trf", "wr"].reduce([]) do |m, t|
31
42
  url = "#{DOMAIN}/searchkey"
32
43
  url += "&type=#{t}" if t
33
- url += "&RefNbr=#{ref}&From=#{from}&To=#{to}&start=1"
34
- m + results(Addressable::URI.parse(url).normalize)
44
+ url += "&RefNbr=#{code}&From=#{from}&To=#{to}&start=1"
45
+ m + results(Addressable::URI.parse(url).normalize, part)
35
46
  end
36
47
  end
37
48
 
38
- def results(uri)
39
- Nokogiri::HTML(OpenURI.open_uri(uri)).css(
40
- "//body/li", "ul.search-results > li", "ul.morethesame > li"
49
+ # @param url [String]
50
+ # @param part [String, nil]
51
+ # @return [Array<RelatonIec::Hit>]
52
+ def results(uri, part)
53
+ contains = "[contains(.,'Part #{part}:')]" if part
54
+ Nokogiri::HTML(OpenURI.open_uri(uri)).xpath(
55
+ "//body/li#{contains}",
56
+ "//ul[contains(@class,'search-results')]/li#{contains}",
57
+ "//ul[contains(@class,'morethesame')]/li#{contains}"
41
58
  ).map { |h| make_hit h }
42
59
  end
43
60
 
@@ -9,10 +9,19 @@ module RelatonIec
9
9
  # Class methods for search ISO standards.
10
10
  class IecBibliography
11
11
  class << self
12
+ ##
13
+ # Search for standards entries. To seach packaged document it needs to
14
+ # pass part parametr.
15
+ #
16
+ # @example Search for packaged standard
17
+ # RelatonIec::IecBibliography.search 'IEC 60050-311', nil, '311'
18
+ #
12
19
  # @param text [String]
20
+ # @param year [String, nil]
21
+ # @param part [String, nil] search for packaged stndard if not nil
13
22
  # @return [RelatonIec::HitCollection]
14
- def search(text, year = nil)
15
- HitCollection.new text, year
23
+ def search(text, year = nil, part = nil)
24
+ HitCollection.new text, year, part
16
25
  rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError
17
26
  raise RelatonBib::RequestError, "Could not access http://www.iec.ch"
18
27
  end
@@ -76,14 +85,20 @@ module RelatonIec
76
85
  workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
77
86
  end
78
87
 
79
- def isobib_search_filter(code)
88
+ def isobib_search_filter(code, year) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
80
89
  docidrx = %r{^(ISO|IEC)[^0-9]*\s[0-9-]+}
81
90
  corrigrx = %r{^(ISO|IEC)[^0-9]*\s[0-9-]+:[0-9]+/}
82
91
  warn "[relaton-iec] (\"#{code}\") fetching..."
83
- result = search(code)
92
+ result = search(code, year)
93
+ if result.empty? && /(?<=-)(?<part>\d+)/ =~ code
94
+ # try to search packaged standard
95
+ result = search code, year, part
96
+ ref = code.sub /(?<=-\d)\d+/, ""
97
+ else ref = code
98
+ end
84
99
  result.select do |i|
85
100
  i.hit[:code] &&
86
- i.hit[:code].match(docidrx).to_s.include?(code) &&
101
+ i.hit[:code].match(docidrx).to_s.include?(ref) &&
87
102
  corrigrx !~ i.hit[:code]
88
103
  end
89
104
  end
@@ -148,7 +163,7 @@ module RelatonIec
148
163
  def iecbib_get1(code, year, _opts)
149
164
  return iev if code.casecmp("IEV").zero?
150
165
 
151
- result = isobib_search_filter(code) || return
166
+ result = isobib_search_filter(code, year) || return
152
167
  ret = isobib_results_filter(result, year)
153
168
  if ret[:ret]
154
169
  warn "[relaton-iec] (\"#{code}\") found "\
@@ -1,3 +1,3 @@
1
1
  module RelatonIec
2
- VERSION = "1.6.0".freeze
2
+ VERSION = "1.7.0".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.6.pre"
38
+ spec.add_dependency "relaton-iso-bib", "~> 1.7.0"
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.6.0
4
+ version: 1.7.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-11-13 00:00:00.000000000 Z
11
+ date: 2020-11-27 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.6.pre
173
+ version: 1.7.0
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.6.pre
180
+ version: 1.7.0
181
181
  description: 'RelatonIec: retrieve IEC Standards for bibliographic use using the IecBibliographicItem
182
182
  model'
183
183
  email: