relaton-iec 1.5.pre → 1.7.1

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: bd9ec230a9a65e92303338c7382f1e5d0f2ff05f4b8f6045df756608051442f7
4
- data.tar.gz: dd2eca3bf6042280bc5ee3b1192ed409192e5db44f64b065a2c2bd3029b7216f
3
+ metadata.gz: 3989d41422ae3287109099dabba99ecc5c8a5657dd391fa6e069e7116df4fdac
4
+ data.tar.gz: 222dd6c957c83b1a6c4bdb0a79140bf33f64da6a1725a7ece785a1fcc797bf31
5
5
  SHA512:
6
- metadata.gz: 89a6fc2e201e79481a4808ca9a5274ea95b5d2d00367852e3560be9babee955618e83cc3652e3600f6b9d008eb86c20763d691ca5c747a51b54fe6b1cb90fe38
7
- data.tar.gz: 79ca4485f6cd1e438c4f3cc4d50690081691491b2e03303e7ac03cfaff49d5722fb050f9928f45c1f978202d715d8a35b4fc4a8b4bd05824836a65e62c72dd25
6
+ metadata.gz: 59b511e74a2315143c1ed8aa5a78e231d7b8fb7a09b568676443b39bd7d077e654fba28ff9c160000beb6ba9868684646ab546af4c26605aa2c06bac5849c827
7
+ data.tar.gz: a9530148a809cb3b898abb86a4b54c9c2c421bdd5a71a0f11ee6000ec93b45731b4bab70c088ee973a1538c42f925d2233f27fa1c71f72abacdb70fba8685584
@@ -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: |
@@ -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,7 +27,7 @@ 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
 
@@ -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"/>
@@ -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">
@@ -42,7 +50,6 @@
42
50
  </define>
43
51
  <define name="xref">
44
52
  <element name="xref">
45
- <!-- attribute target { xsd:IDREF }, -->
46
53
  <attribute name="target">
47
54
  <data type="string">
48
55
  <param name="pattern">\i\c*|\c+#\c+</param>
@@ -142,6 +149,11 @@
142
149
  <data type="boolean"/>
143
150
  </attribute>
144
151
  </optional>
152
+ <optional>
153
+ <attribute name="key">
154
+ <data type="boolean"/>
155
+ </attribute>
156
+ </optional>
145
157
  <oneOrMore>
146
158
  <ref name="dt"/>
147
159
  <ref name="dd"/>
@@ -864,6 +876,13 @@
864
876
  </define>
865
877
  <define name="standard-document">
866
878
  <element name="standard-document">
879
+ <attribute name="version"/>
880
+ <attribute name="type">
881
+ <choice>
882
+ <value>semantic</value>
883
+ <value>presentation</value>
884
+ </choice>
885
+ </attribute>
867
886
  <ref name="bibdata"/>
868
887
  <optional>
869
888
  <ref name="boilerplate"/>
@@ -1158,49 +1177,7 @@
1158
1177
  </define>
1159
1178
  <define name="annex">
1160
1179
  <element name="annex">
1161
- <optional>
1162
- <attribute name="id">
1163
- <data type="ID"/>
1164
- </attribute>
1165
- </optional>
1166
- <optional>
1167
- <attribute name="language"/>
1168
- </optional>
1169
- <optional>
1170
- <attribute name="script"/>
1171
- </optional>
1172
- <optional>
1173
- <attribute name="inline-header">
1174
- <data type="boolean"/>
1175
- </attribute>
1176
- </optional>
1177
- <attribute name="obligation">
1178
- <choice>
1179
- <value>normative</value>
1180
- <value>informative</value>
1181
- </choice>
1182
- </attribute>
1183
- <optional>
1184
- <ref name="section-title"/>
1185
- </optional>
1186
- <group>
1187
- <group>
1188
- <zeroOrMore>
1189
- <ref name="BasicBlock"/>
1190
- </zeroOrMore>
1191
- <zeroOrMore>
1192
- <ref name="note"/>
1193
- </zeroOrMore>
1194
- </group>
1195
- <zeroOrMore>
1196
- <choice>
1197
- <ref name="annex-subsection"/>
1198
- <ref name="terms"/>
1199
- <ref name="definitions"/>
1200
- <ref name="references"/>
1201
- </choice>
1202
- </zeroOrMore>
1203
- </group>
1180
+ <ref name="Annex-Section"/>
1204
1181
  </element>
1205
1182
  </define>
1206
1183
  <define name="terms">
@@ -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"/>
@@ -9,23 +9,62 @@ 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) #(text, hit_pages = nil)
14
- super
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
17
+ end
18
+
19
+ private
20
+
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)
15
26
  from, to = nil
16
27
  if year
17
28
  from = Date.strptime year, "%Y"
18
29
  to = from.next_year.prev_day
19
30
  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)
31
+ get_results ref, from, to, part
32
+ end
33
+
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
41
+ [nil, "trf", "wr"].reduce([]) do |m, t|
42
+ url = "#{DOMAIN}/searchkey"
43
+ url += "&type=#{t}" if t
44
+ url += "&RefNbr=#{code}&From=#{from}&To=#{to}&start=1"
45
+ m + results(Addressable::URI.parse(url).normalize, part)
28
46
  end
29
47
  end
48
+
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}"
58
+ ).map { |h| make_hit h }.compact
59
+ end
60
+
61
+ def make_hit(hit)
62
+ link = hit.at('a[@href!="#"]')
63
+ return unless link
64
+
65
+ code = link.text.tr [194, 160].pack("c*").force_encoding("UTF-8"), ""
66
+ title = hit.xpath("text()").text.gsub(/[\r\n]/, "")
67
+ Hit.new({ code: code, title: title, url: DOMAIN + link[:href] }, self)
68
+ end
30
69
  end
31
70
  end
@@ -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
@@ -136,9 +151,9 @@ module RelatonIec
136
151
  return { ret: r } if !year
137
152
 
138
153
  r.date.select { |d| d.type == "published" }.each do |d|
139
- return { ret: r } if year.to_i == d.on.year
154
+ return { ret: r } if year.to_i == d.on(:year)
140
155
 
141
- missed_years << d.on.year
156
+ missed_years << d.on(:year)
142
157
  end
143
158
  end
144
159
  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 "\
@@ -223,8 +223,7 @@ module RelatonIec
223
223
  def fetch_status_relations(url)
224
224
  pubid = url.match(/\d+$/).to_s
225
225
  uri = URI DOMAIN + "/webstore/webstore.nsf/AjaxRequestXML?"\
226
- "Openagent&url=http://www.iec.ch/dyn/www/f?"\
227
- "p=103:390:::::P390_PUBLICATION_ID:" + pubid
226
+ "Openagent&url=" + pubid
228
227
  resp = Net::HTTP.get_response uri
229
228
  doc = Nokogiri::XML resp.body
230
229
  status = fetch_status doc
@@ -1,3 +1,3 @@
1
1
  module RelatonIec
2
- VERSION = "1.5.pre".freeze
2
+ VERSION = "1.7.1".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.5.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.5.pre
4
+ version: 1.7.1
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-10-07 00:00:00.000000000 Z
11
+ date: 2020-11-30 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.5.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.5.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:
@@ -231,9 +231,9 @@ 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: 1.3.1
236
+ version: '0'
237
237
  requirements: []
238
238
  rubygems_version: 3.0.6
239
239
  signing_key: