relaton-bipm 1.19.1 → 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: 6169158d13f03ec83666123ca52d0e87b7960ba13fe5b6d5051228c54158f93c
4
- data.tar.gz: 46236ffb5e1f875fd042dd89fe866251962a553497dd9a8a474edcd6aa18e2fa
3
+ metadata.gz: d26cb426c0ebdcd6e4544117b76fabc440ce698ae86511d2fa13022fedc0fa33
4
+ data.tar.gz: b0dae1c393906430b924171c4bc9dc0ddc723108372fd7ac351092845153cb6b
5
5
  SHA512:
6
- metadata.gz: d1b01efea043f825d7e08dcecc6396e21b56c75ab0131dffd6b5e936ea10e185e9f8412ddf9c30fa21f64eaf9e97408da92e06fedc2a7cbb1d9da581151ab0ea
7
- data.tar.gz: 8cc33bc1d0b431ecd6d55c640ddcf5d715e640dfd2a926a5e2db5d72f442fefe93f527275f17236e2a815302cdb65ec9c47f71dd970b9d0eb708133765654d92
6
+ metadata.gz: bfcf6fc883da15803965d74ef0faee65f5aabc637b382e55586d63ace8647f988862748a88269fe3bc33c27308c41a2801c5d5bed7c408e736c451e1b7ba1f03
7
+ data.tar.gz: 6a1b674e7285565be0fd400f4b27fa9066483fb2500bea43bde9aec6f8c95aa483602d74946b1acb0a669203467a8739bd8e4e5b11eb2ef01958203058651780
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.19.1".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.1
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-31 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