relaton-bipm 1.7.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/grammars/reqt.rng CHANGED
@@ -30,15 +30,34 @@
30
30
  <data type="boolean"/>
31
31
  </attribute>
32
32
  </optional>
33
+ <optional>
34
+ <attribute name="number"/>
35
+ </optional>
33
36
  <optional>
34
37
  <attribute name="subsequence"/>
35
38
  </optional>
39
+ <optional>
40
+ <attribute name="keep-with-next">
41
+ <data type="boolean"/>
42
+ </attribute>
43
+ </optional>
44
+ <optional>
45
+ <attribute name="keep-lines-together">
46
+ <data type="boolean"/>
47
+ </attribute>
48
+ </optional>
36
49
  <attribute name="id">
37
50
  <data type="ID"/>
38
51
  </attribute>
39
52
  <optional>
40
53
  <attribute name="filename"/>
41
54
  </optional>
55
+ <optional>
56
+ <attribute name="model"/>
57
+ </optional>
58
+ <optional>
59
+ <attribute name="type"/>
60
+ </optional>
42
61
  <optional>
43
62
  <ref name="reqtitle"/>
44
63
  </optional>
@@ -48,9 +67,9 @@
48
67
  <optional>
49
68
  <ref name="subject"/>
50
69
  </optional>
51
- <optional>
70
+ <zeroOrMore>
52
71
  <ref name="reqinherit"/>
53
- </optional>
72
+ </zeroOrMore>
54
73
  <zeroOrMore>
55
74
  <ref name="classification"/>
56
75
  </zeroOrMore>
@@ -135,6 +154,16 @@
135
154
  <data type="boolean"/>
136
155
  </attribute>
137
156
  </optional>
157
+ <optional>
158
+ <attribute name="keep-with-next">
159
+ <data type="boolean"/>
160
+ </attribute>
161
+ </optional>
162
+ <optional>
163
+ <attribute name="keep-lines-together">
164
+ <data type="boolean"/>
165
+ </attribute>
166
+ </optional>
138
167
  <oneOrMore>
139
168
  <ref name="BasicBlock"/>
140
169
  </oneOrMore>
@@ -46,7 +46,7 @@ module RelatonBipm
46
46
  # @return [RelatonBipm::BipmBibliographicItem]
47
47
  def self.from_hash(hash)
48
48
  item_hash = ::RelatonBipm::HashConverter.hash_to_bib(hash)
49
- new **item_hash
49
+ new(**item_hash)
50
50
  end
51
51
 
52
52
  # @param opts [Hash]
@@ -83,7 +83,7 @@ module RelatonBipm
83
83
  # @param prefix [String]
84
84
  # @return [String]
85
85
  def to_asciibib(prefix = "")
86
- pref = prefix.empty? ? prefix : prefix + "."
86
+ pref = prefix.empty? ? prefix : "#{prefix}."
87
87
  out = super
88
88
  out += comment_period.to_asciibib prefix if comment_period
89
89
  out += "#{pref}si_aspect:: #{si_aspect}\n" if si_aspect
@@ -4,38 +4,11 @@ module RelatonBipm
4
4
  class BipmBibliography
5
5
  GH_ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/master/data/".freeze
6
6
  IOP_DOMAIN = "https://iopscience.iop.org".freeze
7
- USERAGENTS = [
8
- "Mozilla/5.0 CK={} (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
9
- "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
10
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
11
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
12
- "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
13
- "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; KTXN)",
14
- "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1",
15
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
16
- "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0",
17
- "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1",
18
- "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36",
19
- "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
20
- "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
21
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko)",
22
- "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
23
- "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",
24
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
25
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko)",
26
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)",
27
- "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko",
28
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)",
29
- "Mozilla/5.0 (Linux; U; Android 2.2) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
30
- "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36",
31
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1",
32
- "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)",
33
- ].freeze
34
7
 
35
8
  class << self
36
9
  # @param text [String]
37
10
  # @return [RelatonBipm::BipmBibliographicItem]
38
- def search(text, _year = nil, _opts = {})
11
+ def search(text, _year = nil, _opts = {}) # rubocop:disable Metrics/AbcSize
39
12
  warn "[relaton-bipm] (\"#{text}\") fetching..."
40
13
  ref = text.sub(/^BIPM\s/, "")
41
14
  item = ref.match?(/^Metrologia/i) ? get_metrologia(ref, magent) : get_bipm(ref, magent)
@@ -48,7 +21,7 @@ module RelatonBipm
48
21
  end
49
22
 
50
23
  # @return [Mechanize]
51
- def magent
24
+ def magent # rubocop:disable Metrics/MethodLength
52
25
  a = Mechanize.new
53
26
  a.request_headers = {
54
27
  "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,"\
@@ -57,8 +30,8 @@ module RelatonBipm
57
30
  "Accept-Language" => "en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7",
58
31
  "Cache-Control" => "max-age=0",
59
32
  "Upgrade-Insecure-Requests" => "1",
60
- "User-Agent" => USERAGENTS.shuffle.first,
61
33
  }
34
+ a.user_agent_alias = Mechanize::AGENT_ALIASES.map(&:first).shuffle.first
62
35
  a
63
36
  end
64
37
 
@@ -66,12 +39,12 @@ module RelatonBipm
66
39
  # @param agent [Mechanize]
67
40
  # @return [RelatonBipm::BipmBibliographicItem]
68
41
  def get_bipm(ref, agent)
69
- url = "#{GH_ENDPOINT}#{ref.downcase.split(' ').join '-'}.yaml"
42
+ url = "#{GH_ENDPOINT}#{ref.downcase.split.join '-'}.yaml"
70
43
  resp = agent.get url
71
44
  return unless resp.code == "200"
72
45
 
73
46
  bib_hash = HashConverter.hash_to_bib YAML.safe_load(resp.body, [Date])
74
- BipmBibliographicItem.new **bib_hash
47
+ BipmBibliographicItem.new(**bib_hash)
75
48
  end
76
49
 
77
50
  # @param ref [String]
@@ -79,7 +52,7 @@ module RelatonBipm
79
52
  # @return [RelatonBipm::BipmBibliographicItem]
80
53
  def get_metrologia(ref, agent)
81
54
  agent.redirect_ok = false
82
- ref_arr = ref.split(" ")
55
+ ref_arr = ref.split
83
56
  case ref_arr.size
84
57
  when 1 then get_journal agent
85
58
  when 2 then get_volume ref_arr[1], agent
@@ -91,7 +64,7 @@ module RelatonBipm
91
64
  # @param agent [Mechanize]
92
65
  # @return [RelatonBipm::BipmBibliographicItem]
93
66
  def get_journal(agent)
94
- url = IOP_DOMAIN + "/journal/0026-1394"
67
+ url = "#{IOP_DOMAIN}/journal/0026-1394"
95
68
  rsp = agent.get url
96
69
  rel = rsp.xpath('//select[@id="allVolumesSelector"]/option').map do |v|
97
70
  { type: "partOf", bibitem: journal_rel(v) }
@@ -129,7 +102,7 @@ module RelatonBipm
129
102
  docid = doc_id [vol, ish]
130
103
  t = elm.at "p"
131
104
  title_fref = t ? { title: titles(t.text) } : { formattedref: fref(docid.id) }
132
- BipmBibliographicItem.new **title_fref, docid: [docid], link: blink(url)
105
+ BipmBibliographicItem.new(**title_fref, docid: [docid], link: blink(url))
133
106
  end
134
107
 
135
108
  # @param title [String]
@@ -234,10 +207,10 @@ module RelatonBipm
234
207
  # @param agent [Mechanize]
235
208
  # @return [RelatonBipm::BipmBibliographicItem]
236
209
  def get_article(path, vol, ish, agent) # rubocop:disable Metrics/AbcSize
237
- url = URI IOP_DOMAIN + path
238
- rsp = agent.get url
210
+ rsp = agent.get path
211
+ url = rsp.uri
239
212
  bib = rsp.link_with(text: "BibTeX").href
240
- rsp = agent.get URI IOP_DOMAIN + bib
213
+ rsp = agent.get bib
241
214
  bt = BibTeX.parse(rsp.body).first
242
215
  bibitem(docid: btdocid(bt), title: titles(bt.title.to_s), abstract: btabstract(bt), doctype: bt.type.to_s,
243
216
  link: btlink(bt, url), date: btdate(bt), contributor: btcontrib(bt), series: series,
@@ -248,7 +221,7 @@ module RelatonBipm
248
221
  # @return [RelatonBipm::BipmBibliographicItem]
249
222
  def bibitem(**args)
250
223
  BipmBibliographicItem.new(
251
- fetched: Date.today.to_s, type: "standard", language: ["en"], script: ["Latn"], **args
224
+ fetched: Date.today.to_s, type: "standard", language: ["en"], script: ["Latn"], **args,
252
225
  )
253
226
  end
254
227
 
@@ -291,7 +264,7 @@ module RelatonBipm
291
264
  # @return [Array<Hash>]
292
265
  def btcontrib(bibtex)
293
266
  surname, initial = bibtex.author.split ", "
294
- initial = initial.split(" ").map { |i| RelatonBib::LocalizedString.new i, "en", "Latn" }
267
+ initial = initial.split.map { |i| RelatonBib::LocalizedString.new i, "en", "Latn" }
295
268
  surname = RelatonBib::LocalizedString.new surname, "en", "Latn"
296
269
  name = RelatonBib::FullName.new surname: surname, initial: initial
297
270
  author = RelatonBib::Person.new name: name
@@ -31,7 +31,7 @@ module RelatonBipm
31
31
  # @param prefix [String]
32
32
  # @return [String]
33
33
  def to_asciibib(prefix)
34
- pref = prefix.empty? ? prefix : prefix + "."
34
+ pref = prefix.empty? ? prefix : "#{prefix}."
35
35
  pref += "commentperiod"
36
36
  out = "#{pref}.from:: #{from}\n"
37
37
  out += "#{pref}.to:: #{to}\n" if to
@@ -28,7 +28,7 @@ module RelatonBipm
28
28
  # @param count [Integer]
29
29
  # @return [String]
30
30
  def to_asciibib(prefix, count = 1)
31
- pref = prefix.empty? ? prefix : prefix + "."
31
+ pref = prefix.empty? ? prefix : "#{prefix}."
32
32
  pref += "committee"
33
33
  out = count > 1 ? "#{pref}::\n" : ""
34
34
  out += "#{pref}.acronym:: #{acronym}\n"
@@ -39,8 +39,9 @@ module RelatonBipm
39
39
  def to_hash
40
40
  hash = { "acronym" => acronym }
41
41
  cnt = content.to_hash
42
- if cnt.is_a? Array then hash["variants"] = cnt
43
- elsif cnt.is_a? Hash then hash.merge! cnt
42
+ case cnt
43
+ when Array then hash["variants"] = cnt
44
+ when Hash then hash.merge! cnt
44
45
  else hash["content"] = cnt
45
46
  end
46
47
  hash
@@ -23,7 +23,7 @@ module RelatonBipm
23
23
  # @param prefix [String]
24
24
  # @return [String]
25
25
  def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize
26
- pref = prefix.empty? ? prefix : prefix + "."
26
+ pref = prefix.empty? ? prefix : "#{prefix}."
27
27
  pref += "editorialgroup"
28
28
  out = ""
29
29
  committee.each { |c| out += c.to_asciibib pref, committee.size }
@@ -23,14 +23,13 @@ module RelatonBipm
23
23
  # @param item_hash [Hash]
24
24
  # @return [RelatonBib::BibliographicItem]
25
25
  def bib_item(item_hash)
26
- BipmBibliographicItem.new **item_hash
26
+ BipmBibliographicItem.new(**item_hash)
27
27
  end
28
28
 
29
29
  # @param ret [Hash]
30
30
  def title_hash_to_bib(ret)
31
- ret[:title] &&= array(ret[:title]).reduce(
32
- RelatonBib::TypedTitleStringCollection.new
33
- ) do |m, t|
31
+ ret[:title] &&= array(ret[:title])
32
+ .reduce(RelatonBib::TypedTitleStringCollection.new) do |m, t|
34
33
  m << if t.is_a? Hash
35
34
  RelatonBib::TypedTitleString.new(**t)
36
35
  else
@@ -55,16 +54,14 @@ module RelatonBipm
55
54
  # @param ret [Hash]
56
55
  def dates_hash_to_bib(ret)
57
56
  super
58
- ret[:date] &&= ret[:date].map do |d|
59
- BibliographicDate.new **d
60
- end
57
+ ret[:date] &&= ret[:date].map { |d| BibliographicDate.new(**d) }
61
58
  end
62
59
 
63
60
  # @param ret [Hash]
64
61
  def relations_hash_to_bib(ret)
65
62
  super
66
63
  ret[:relation] &&= ret[:relation].map do |r|
67
- RelatonBipm::DocumentRelation.new **r
64
+ RelatonBipm::DocumentRelation.new(**r)
68
65
  end
69
66
  end
70
67
 
@@ -77,7 +74,7 @@ module RelatonBipm
77
74
  content = RelatonBib::LocalizedString.new vars
78
75
  Committee.new acronym: c[:acronym], content: content
79
76
  else
80
- Committee.new **c
77
+ Committee.new(**c)
81
78
  end
82
79
  end
83
80
  wg = array(ret[:editorialgroup][:workgroup]).map do |w|
@@ -100,7 +97,7 @@ module RelatonBipm
100
97
  # @param ret [Hash]
101
98
  def structuredidentifier_hash_to_bib(ret)
102
99
  ret[:structuredidentifier] &&= StructuredIdentifier.new(
103
- **ret[:structuredidentifier]
100
+ **ret[:structuredidentifier],
104
101
  )
105
102
  end
106
103
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.7.2".freeze
2
+ VERSION = "1.9.0".freeze
3
3
  end
@@ -20,7 +20,7 @@ module RelatonBipm
20
20
  # @param item_hash [Hash]
21
21
  # @return [RelatonBipm::BipmBibliographicItem]
22
22
  def bib_item(item_hash)
23
- BipmBibliographicItem.new **item_hash
23
+ BipmBibliographicItem.new(**item_hash)
24
24
  end
25
25
 
26
26
  # @param item [Nokogiri::XML::Element]
data/relaton_bipm.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
12
12
  "bibliographic use using the BibliographicItem model"
13
13
  spec.homepage = "https://github.com/relaton/relaton-bipm"
14
14
  spec.license = "BSD-2-Clause"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
18
 
@@ -36,14 +36,14 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
36
36
  # spec.add_development_dependency "debase"
37
37
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
38
38
  spec.add_development_dependency "pry-byebug"
39
- spec.add_development_dependency "rake", "~> 10.0"
39
+ # spec.add_development_dependency "rake", "~> 13.0"
40
40
  # spec.add_development_dependency "ruby-debug-ide"
41
41
  spec.add_development_dependency "ruby-jing"
42
42
  spec.add_development_dependency "simplecov"
43
43
  spec.add_development_dependency "vcr"
44
44
  spec.add_development_dependency "webmock"
45
45
 
46
- spec.add_dependency "mechanize", "~> 2.7.6"
47
- spec.add_dependency "relaton-bib", "~> 1.7.0"
46
+ spec.add_dependency "mechanize", "~> 2.8.0"
47
+ spec.add_dependency "relaton-bib", "~> 1.9.0"
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.7.2
4
+ version: 1.9.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: 2021-03-20 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '10.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '10.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: ruby-jing
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,28 +114,28 @@ dependencies:
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: 2.7.6
117
+ version: 2.8.0
132
118
  type: :runtime
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: 2.7.6
124
+ version: 2.8.0
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: relaton-bib
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: 1.7.0
131
+ version: 1.9.0
146
132
  type: :runtime
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: 1.7.0
138
+ version: 1.9.0
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: serrano
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -218,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
204
  requirements:
219
205
  - - ">="
220
206
  - !ruby/object:Gem::Version
221
- version: 2.4.0
207
+ version: 2.5.0
222
208
  required_rubygems_version: !ruby/object:Gem::Requirement
223
209
  requirements:
224
210
  - - ">="