relaton-bipm 1.10.0 → 1.10.3

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: 62e2b0e8e3e760434471aee77019fa507d36cab63dc64efe988723adc198c87a
4
- data.tar.gz: 305943e857f09997c5d883967ef2bc25904ff6958bce9ccd2788199aa1b3cbee
3
+ metadata.gz: 82921528d18ccbfc6bbba60ae832fd711d92c9d338b887c19b500d81f911098b
4
+ data.tar.gz: 21db3cbf7e095003a51224b8c7c8a11f0b46164d52f161f45c83acd5677b65ad
5
5
  SHA512:
6
- metadata.gz: 5ecfd3a440ccd9d40d88b93a8621e5cac30b340acccc18cad7f44fd383334f0354f3ceb7963b99b4dc4eb58ff9a397565d940dd3d1463304faa1358a0dd78967
7
- data.tar.gz: 013f356a1d17c03058f359b7e9ce20b5338d45e90f25a9bcbc8481239acad75949b26472bf1bf654dcfae868197702f7c0337e186ca0137a108683e18b8cadf9
6
+ metadata.gz: 5df3c90e1dce934b765a738283b8cefc1de1516ffc869698bc5c161ca5a3ae290a30f799c00de19fe67513d589934ea469d3a9a4c5c3144e1afc6ca3174eea7b
7
+ data.tar.gz: 5516be3766704271ef92b49621fdf4ee38e01520ba986917f8ff0a8fd4d34eabb3530dadb8fc500dbbedf762d0128115c3987476cb430930c21cbe516e248cab
data/README.adoc CHANGED
@@ -8,7 +8,7 @@ image:https://codeclimate.com/github/relaton/relaton-bipm/badges/gpa.svg["Code C
8
8
  image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-bipm.svg["Pull Requests", link="https://github.com/relaton/relaton-bipm/pulls"]
9
9
  image:https://img.shields.io/github/commits-since/relaton/relaton-bipm/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-bipm/releases"]
10
10
 
11
- RelatonIec is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
11
+ RelatonBipm is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
12
12
 
13
13
  You can use it to retrieve metadata of BIPM Standards from https://www.bipm.org, and access such metadata through the `BipmBibliographicItem` object.
14
14
 
@@ -53,17 +53,17 @@ bib = RelatonBipm::BipmBibliography.get "BIPM Metrologia 29 6 373"
53
53
  ...
54
54
 
55
55
  # get CGPM resolutions
56
- RelatonBipm::BipmBibliography.get "BIPM CGPM01 1"
57
- [relaton-bipm] ("BIPM CGPM01 1") fetching...
58
- [relaton-bipm] ("BIPM CGPM01 1") found CGPM01-1
59
- => #<RelatonBipm::BipmBibliographicItem:0x00007f9e92817968
56
+ RelatonBipm::BipmBibliography.get "BIPM CR 01"
57
+ [relaton-bipm] ("BIPM CR 01") fetching...
58
+ [relaton-bipm] ("BIPM CR 01") found BIPM CR 01
59
+ => #<RelatonBipm::BipmBibliographicItem:0x00007fd4f7cba038
60
60
  ...
61
61
 
62
62
  # get CIPM resolutions
63
- RelatonBipm::BipmBibliography.get "BIPM CIPM101 1"
64
- [relaton-bipm] ("BIPM CIPM101 1") fetching...
65
- [relaton-bipm] ("BIPM CIPM101 1") found CIPM101-1
66
- => #<RelatonBipm::BipmBibliographicItem:0x00007f9e9293d658
63
+ RelatonBipm::BipmBibliography.get "BIPM PV 101(I)"
64
+ [relaton-bipm] ("BIPM PV 101(I)") fetching...
65
+ [relaton-bipm] ("BIPM PV 101(I)") found BIPM PV 101(I)
66
+ => #<RelatonBipm::BipmBibliographicItem:0x00007fd5072301c0
67
67
  ...
68
68
  ----
69
69
 
data/grammars/biblio.rng CHANGED
@@ -209,9 +209,6 @@
209
209
  <zeroOrMore>
210
210
  <ref name="contact"/>
211
211
  </zeroOrMore>
212
- <zeroOrMore>
213
- <ref name="uri"/>
214
- </zeroOrMore>
215
212
  </element>
216
213
  </define>
217
214
  <define name="fullname">
@@ -828,6 +825,11 @@
828
825
  <optional>
829
826
  <attribute name="scope"/>
830
827
  </optional>
828
+ <optional>
829
+ <attribute name="primary">
830
+ <data type="boolean"/>
831
+ </attribute>
832
+ </optional>
831
833
  <text/>
832
834
  </element>
833
835
  </define>
@@ -39,12 +39,18 @@ module RelatonBipm
39
39
  # @param ref [String]
40
40
  # @param agent [Mechanize]
41
41
  # @return [RelatonBipm::BipmBibliographicItem]
42
- def get_bipm(ref, agent)
42
+ def get_bipm(ref, agent) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
43
43
  url = "#{GH_ENDPOINT}#{ref.upcase.split.join '-'}.yaml"
44
44
  resp = agent.get url
45
+ check_response resp
45
46
  return unless resp.code == "200"
46
47
 
47
- bib_hash = HashConverter.hash_to_bib YAML.safe_load(resp.body, [Date])
48
+ yaml = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0.pre1")
49
+ YAML.safe_load(resp.body, permitted_classes: [Date])
50
+ else
51
+ YAML.safe_load(resp.body, [Date])
52
+ end
53
+ bib_hash = HashConverter.hash_to_bib yaml
48
54
  BipmBibliographicItem.new(**bib_hash)
49
55
  end
50
56
 
@@ -67,6 +73,7 @@ module RelatonBipm
67
73
  def get_journal(agent)
68
74
  url = "#{IOP_DOMAIN}/journal/0026-1394"
69
75
  rsp = agent.get url
76
+ check_response rsp
70
77
  rel = rsp.xpath('//select[@id="allVolumesSelector"]/option').map do |v|
71
78
  { type: "partOf", bibitem: journal_rel(v) }
72
79
  end
@@ -88,6 +95,7 @@ module RelatonBipm
88
95
  def get_volume(vol, agent)
89
96
  url = "#{IOP_DOMAIN}/volume/0026-1394/#{vol}"
90
97
  rsp = agent.get url
98
+ check_response rsp
91
99
  rel = rsp.xpath('//li[@itemprop="hasPart"]').map do |i|
92
100
  { type: "partOf", bibitem: volume_rel(i, vol) }
93
101
  end
@@ -116,9 +124,10 @@ module RelatonBipm
116
124
  # @param ish [String]
117
125
  # @param agent [Mechanize]
118
126
  # @return [RelatonBipm::BipmBibliographicItem]
119
- def get_issue(vol, ish, agent) # rubocop:disable Metrics/AbcSize
127
+ def get_issue(vol, ish, agent) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
120
128
  url = issue_url vol, ish
121
129
  rsp = agent.get url
130
+ check_response rsp
122
131
  rel = rsp.xpath('//div[@class="art-list-item-body"]').map do |a|
123
132
  { type: "partOf", bibitem: issue_rel(a, vol, ish) }
124
133
  end
@@ -188,7 +197,7 @@ module RelatonBipm
188
197
  # @return [RelatonBib::DocumentIdentifier]
189
198
  def doc_id(args)
190
199
  id = args.clone.unshift "Metrologia"
191
- RelatonBib::DocumentIdentifier.new(type: "BIPM", id: id.join(" "))
200
+ RelatonBib::DocumentIdentifier.new(type: "BIPM", id: id.join(" "), primary: true)
192
201
  end
193
202
 
194
203
  # @param vol [String]
@@ -199,6 +208,7 @@ module RelatonBipm
199
208
  def get_article_from_issue(vol, ish, art, agent)
200
209
  url = issue_url vol, ish
201
210
  rsp = agent.get url
211
+ check_response rsp
202
212
  get_article rsp.at("//div[@class='indexer'][.='#{art}']/../div/a")[:href], vol, ish, agent
203
213
  end
204
214
 
@@ -209,9 +219,11 @@ module RelatonBipm
209
219
  # @return [RelatonBipm::BipmBibliographicItem]
210
220
  def get_article(path, vol, ish, agent) # rubocop:disable Metrics/AbcSize
211
221
  rsp = agent.get path
222
+ check_response rsp
212
223
  url = rsp.uri
213
224
  bib = rsp.link_with(text: "BibTeX").href
214
225
  rsp = agent.get bib
226
+ check_response rsp
215
227
  bt = BibTeX.parse(rsp.body).first
216
228
  bibitem(docid: btdocid(bt), title: titles(bt.title.to_s), abstract: btabstract(bt), doctype: bt.type.to_s,
217
229
  link: btlink(bt, url), date: btdate(bt), contributor: btcontrib(bt), series: series,
@@ -293,6 +305,26 @@ module RelatonBipm
293
305
  def get(ref, year = nil, opts = {})
294
306
  search(ref, year, opts)
295
307
  end
308
+
309
+ private
310
+
311
+ #
312
+ # Check HTTP response. Warn and rise error if response is not 200
313
+ # or redirect to CAPTCHA.
314
+ #
315
+ # @param [Mechanize] rsp response
316
+ #
317
+ # @raise [RelatonBib::RequestError] if response is not 200
318
+ #
319
+ def check_response(rsp) # rubocop:disable Metrics/AbcSize
320
+ if rsp.code == "302"
321
+ warn "[relaton-bipm] #{rsp.uri} is redirected to #{rsp.header['location']}"
322
+ raise RelatonBib::RequestError, "redirected to #{rsp.header['location']}"
323
+ elsif rsp.code != "200"
324
+ warn "[read_bipm] can't acces #{rsp.uri} #{rsp.code}"
325
+ raise RelatonBib::RequestError, "can't acces #{rsp.uri} #{rsp.code}"
326
+ end
327
+ end
296
328
  end
297
329
  end
298
330
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.10.0".freeze
2
+ VERSION = "1.10.3".freeze
3
3
  end
data/relaton_bipm.gemspec CHANGED
@@ -44,6 +44,6 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
44
44
  spec.add_development_dependency "webmock"
45
45
 
46
46
  spec.add_dependency "mechanize", "~> 2.8.0"
47
- spec.add_dependency "relaton-bib", "~> 1.10.0"
47
+ spec.add_dependency "relaton-bib", "~> 1.10.1"
48
48
  spec.add_dependency "serrano", "~> 1.0"
49
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bipm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.10.3
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-01-30 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.10.0
131
+ version: 1.10.1
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.10.0
138
+ version: 1.10.1
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: serrano
141
141
  requirement: !ruby/object:Gem::Requirement