relaton-bipm 1.19.0 → 1.19.2

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: f192fd171fc919d9b30fabc3ba8f0e17ecc1a3c58e0ade979f42847c4266ed06
4
- data.tar.gz: bcf449487cef0842578309f4c00305ac25dd0da5154748c662c2499a1e04cc21
3
+ metadata.gz: d26cb426c0ebdcd6e4544117b76fabc440ce698ae86511d2fa13022fedc0fa33
4
+ data.tar.gz: b0dae1c393906430b924171c4bc9dc0ddc723108372fd7ac351092845153cb6b
5
5
  SHA512:
6
- metadata.gz: 0da90de53422e0c080b29fb73cd5472a36018beeece575afe413eac28a698497b7be6d7a3ba352684d7dda6467136be08a3f6bfe0ef99a992991303a54257cc5
7
- data.tar.gz: 866df7ec30e56762cc588bb710450b2dcf58ca2b8f066f9473410957f340034856e8426d7705223fc44357c4142d54fca88525554ca3fa649363cdde80929978
6
+ metadata.gz: bfcf6fc883da15803965d74ef0faee65f5aabc637b382e55586d63ace8647f988862748a88269fe3bc33c27308c41a2801c5d5bed7c408e736c451e1b7ba1f03
7
+ data.tar.gz: 6a1b674e7285565be0fd400f4b27fa9066483fb2500bea43bde9aec6f8c95aa483602d74946b1acb0a669203467a8739bd8e4e5b11eb2ef01958203058651780
@@ -2,7 +2,7 @@ require "mechanize"
2
2
 
3
3
  module RelatonBipm
4
4
  class BipmBibliography
5
- GH_ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/master/".freeze
5
+ GH_ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/main/".freeze
6
6
  INDEX_FILE = "index2.yaml".freeze
7
7
 
8
8
  class << self
@@ -1,27 +1,31 @@
1
1
  module RelatonBipm
2
- class Committee
2
+ class Committee < RelatonBib::LocalizedString
3
+ ACRONYMS = YAML.load_file File.join(__dir__, "acronyms.yaml")
4
+
3
5
  # @return [String]
4
6
  attr_reader :acronym
5
7
 
6
8
  # @return [RelatonBib::LocalizedString]
7
9
  attr_reader :content
8
10
 
9
- # @param acronym [String]
10
- # @param content [RelatonBib::LocalisedString, String, nil]
11
- def initialize(acronym:, content: nil)
12
- acronyms = YAML.load_file File.join(__dir__, "acronyms.yaml")
13
- unless acronyms[acronym]
11
+ # @param [String] acronym
12
+ # @param [Hash] args
13
+ # @option args [RelatonBib::LocalisedString, String, nil] :content
14
+ # @option args [String, nil] :language
15
+ # @option args [String, nil] :script
16
+ def initialize(acronym:, **args)
17
+ unless ACRONYMS[acronym]
14
18
  Util.warn "Invalid acronym: `#{acronym}`. Allowed " \
15
- "values: `#{acronyms.map { |k, _v| k }.join '`, `'}`"
19
+ "values: `#{ACRONYMS.map { |k, _v| k }.join '`, `'}`"
16
20
  end
17
21
 
18
22
  @acronym = acronym
19
- @content = localized_content content, acronyms[acronym]
23
+ super(*localized_args(acronym, **args))
20
24
  end
21
25
 
22
26
  # @param builder [Nokogiri::XML::Builder]
23
27
  def to_xml(builder)
24
- builder.committee(acronym: acronym) { |b| content.to_xml b }
28
+ builder.committee(acronym: acronym) { |b| super b }
25
29
  end
26
30
 
27
31
  # @param prefix [String]
@@ -32,13 +36,13 @@ module RelatonBipm
32
36
  pref += "committee"
33
37
  out = count > 1 ? "#{pref}::\n" : ""
34
38
  out += "#{pref}.acronym:: #{acronym}\n"
35
- out + content.to_asciibib(pref)
39
+ out + super(pref)
36
40
  end
37
41
 
38
42
  # @return [Hash]
39
43
  def to_hash
40
44
  hash = { "acronym" => acronym }
41
- cnt = content.to_hash
45
+ cnt = super
42
46
  case cnt
43
47
  when Array then hash["variants"] = cnt
44
48
  when Hash then hash.merge! cnt
@@ -49,12 +53,14 @@ module RelatonBipm
49
53
 
50
54
  private
51
55
 
52
- def localized_content(cnt, acr)
53
- if cnt.is_a? String
54
- RelatonBib::LocalizedString.new cnt
55
- elsif (cnt.nil? || cnt.empty?) && acr && acr["en"]
56
- RelatonBib::LocalizedString.new(acr["en"], "en", "Latn")
57
- else cnt
56
+ def localized_args(accronym, **args)
57
+ if args[:content].is_a? String
58
+ [args[:content], args[:language], args[:script]]
59
+ elsif args[:content].nil?
60
+ lang = args[:language] || ACRONYMS.dig(acronym, "en") ? "en" : ACRONYMS[acronym]&.keys&.first
61
+ script = args[:script] || lang == "en" ? "Latn" : nil
62
+ [ACRONYMS.dig(accronym, lang), lang, script]
63
+ else [args[:content]]
58
64
  end
59
65
  end
60
66
  end
@@ -73,8 +73,7 @@ module RelatonBipm
73
73
 
74
74
  cmt = ret[:editorialgroup][:committee].map do |c|
75
75
  if (vars = committee_variants c).any?
76
- content = RelatonBib::LocalizedString.new vars
77
- Committee.new acronym: c[:acronym], content: content
76
+ Committee.new acronym: c[:acronym], content: vars
78
77
  else
79
78
  Committee.new(**c)
80
79
  end
@@ -161,10 +161,9 @@ module RelatonBipm
161
161
  # @return [RelatonBib::FullName] full name
162
162
  #
163
163
  def fullname(name)
164
- fname = forename name.at("./given-names")
165
- sname = name.at("./surname").text
166
- surname = RelatonBib::LocalizedString.new sname, "en", "Latn"
167
- RelatonBib::FullName.new surname: surname, forename: fname
164
+ cname = [name.at("./given-names"), name.at("./surname")].compact.map(&:text).join(" ")
165
+ completename = RelatonBib::LocalizedString.new cname, "en", "Latn"
166
+ RelatonBib::FullName.new completename: completename
168
167
  end
169
168
 
170
169
  #
@@ -31,7 +31,7 @@ module RelatonBipm
31
31
  def fetch_articles # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
32
32
  Dir["#{DIR}/**/*.xml"].each do |path|
33
33
  item = ArticleParser.parse path
34
- file = "#{item.docidentifier.first.id.downcase.gsub(' ', '-')}.#{@data_fetcher.ext}"
34
+ file = "#{item.docidentifier.first.id.downcase.tr(' ', '-')}.#{@data_fetcher.ext}"
35
35
  out_path = File.join(@data_fetcher.output, file)
36
36
  key = Id.new.parse(item.docidentifier.first.id).to_hash
37
37
  @data_fetcher.index2.add_or_update key, out_path
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.19.0".freeze
2
+ VERSION = "1.19.2".freeze
3
3
  end
@@ -58,12 +58,9 @@ module RelatonBipm
58
58
 
59
59
  cm = eg.xpath("committee").map do |c|
60
60
  vars = variants c
61
- cnt = if vars.any?
62
- RelatonBib::LocalizedString.new vars
63
- else
64
- RelatonBib::LocalizedString.new c.text, c[:language], c[:script]
65
- end
66
- Committee.new acronym: c[:acronym], content: cnt
61
+ cnt = vars.any? ? vars : c.text
62
+ args = c.to_h.transform_keys(&:to_sym).select { |k, _| %i[language script locale].include?(k) }
63
+ Committee.new acronym: c[:acronym], content: cnt, **args
67
64
  end
68
65
  wg = eg.xpath("workgroup").map do |w|
69
66
  WorkGroup.new content: w.text, acronym: w[:acronym]
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.19.0
4
+ version: 1.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-03 00:00:00.000000000 Z
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday