relaton-bipm 1.6.pre1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ module RelatonBipm
2
+ class Committee
3
+ # @return [String]
4
+ attr_reader :acronym
5
+
6
+ # @return [RelatonBib::LocalizedString]
7
+ attr_reader :content
8
+
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]
14
+ warn "[relaton-bipm] WARNING: invalid acronym: #{acronym}. Allowed "\
15
+ "values: #{acronyms.map { |k, _v| k }.join ', '}"
16
+ end
17
+
18
+ @acronym = acronym
19
+ @content = localized_content content, acronyms[acronym]
20
+ end
21
+
22
+ # @param builder [Nokogiri::XML::Builder]
23
+ def to_xml(builder)
24
+ builder.committee(acronym: acronym) { |b| content.to_xml b }
25
+ end
26
+
27
+ # @param prefix [String]
28
+ # @param count [Integer]
29
+ # @return [String]
30
+ def to_asciibib(prefix, count = 1)
31
+ pref = prefix.empty? ? prefix : prefix + "."
32
+ pref += "committee"
33
+ out = count > 1 ? "#{pref}::\n" : ""
34
+ out += "#{pref}.acronym:: #{acronym}\n"
35
+ out + content.to_asciibib(pref)
36
+ end
37
+
38
+ # @return [Hash]
39
+ def to_hash
40
+ hash = { "acronym" => acronym }
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
44
+ else hash["content"] = cnt
45
+ end
46
+ hash
47
+ end
48
+
49
+ private
50
+
51
+ def localized_content(cnt, acr)
52
+ if cnt.is_a? String
53
+ RelatonBib::LocalizedString.new cnt
54
+ elsif (cnt.nil? || cnt.empty?) && acr && acr["en"]
55
+ RelatonBib::LocalizedString.new(acr["en"], "en", "Latn")
56
+ else cnt
57
+ end
58
+ end
59
+ end
60
+ end
@@ -2,21 +2,12 @@ module RelatonBipm
2
2
  class EditorialGroup
3
3
  include RelatonBib
4
4
 
5
- COMMITTEES = %w[CGPM CIPM BIPM CCAUV CCEM CCL CCM CCPR CCQM CCRI CCT CCTF
6
- CCU CCL-CCT JCGM JCRB JCTLM INetQI].freeze
7
-
8
5
  # @return [Array<String>]
9
6
  attr_reader :committee, :workgroup
10
7
 
11
- # @param committee [Array<String>]
12
- # @param workgroup [Array<String>]
13
- def initialize(committee:, workgroup:)
14
- committee.each do |c|
15
- unless COMMITTEES.include? c
16
- warn "[relaton-bipm] invalid committee: #{c}"
17
- end
18
- end
19
-
8
+ # @param committee [Array<RelatonBipm::Committee>]
9
+ # @param workgroup [Array<RelatonBipm::WorkGroup>]
10
+ def initialize(committee:, workgroup: [])
20
11
  @committee = committee
21
12
  @workgroup = workgroup
22
13
  end
@@ -24,19 +15,19 @@ module RelatonBipm
24
15
  # @param builder [Nokogiri::XML::Builder]
25
16
  def to_xml(builder)
26
17
  builder.editorialgroup do |b|
27
- committee.each { |c| b.committee c }
28
- workgroup.each { |c| b.workgroup c }
18
+ committee.each { |c| c.to_xml b }
19
+ workgroup.each { |c| c.to_xml b }
29
20
  end
30
21
  end
31
22
 
32
23
  # @param prefix [String]
33
24
  # @return [String]
34
- def to_asciibib(prefix = "")
25
+ def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize
35
26
  pref = prefix.empty? ? prefix : prefix + "."
36
27
  pref += "editorialgroup"
37
28
  out = ""
38
- committee.each { |c| out += "#{pref}.committee:: #{c}\n" }
39
- workgroup.each { |w| out += "#{pref}.workgroup:: #{w}\n" }
29
+ committee.each { |c| out += c.to_asciibib pref, committee.size }
30
+ workgroup.each { |w| out += w.to_asciibib pref, workgroup.size }
40
31
  out
41
32
  end
42
33
 
@@ -2,6 +2,8 @@ require "yaml"
2
2
 
3
3
  module RelatonBipm
4
4
  class HashConverter < RelatonBib::HashConverter
5
+ @@acronyms = nil
6
+
5
7
  class << self
6
8
  # @override RelatonIsoBib::HashConverter.hash_to_bib
7
9
  # @param args [Hash]
@@ -21,7 +23,7 @@ module RelatonBipm
21
23
  # @param item_hash [Hash]
22
24
  # @return [RelatonBib::BibliographicItem]
23
25
  def bib_item(item_hash)
24
- BipmBibliographicItem.new item_hash
26
+ BipmBibliographicItem.new **item_hash
25
27
  end
26
28
 
27
29
  # @param ret [Hash]
@@ -30,7 +32,7 @@ module RelatonBipm
30
32
  RelatonBib::TypedTitleStringCollection.new
31
33
  ) do |m, t|
32
34
  m << if t.is_a? Hash
33
- RelatonBib::TypedTitleString.new(t)
35
+ RelatonBib::TypedTitleString.new(**t)
34
36
  else
35
37
  RelatonBib::TypedTitleString.new(content: t)
36
38
  end
@@ -39,7 +41,7 @@ module RelatonBipm
39
41
 
40
42
  # @param ret [Hash]
41
43
  def commentperiod_hash_to_bib(ret)
42
- ret[:comment_period] &&= CommentPeriond.new(ret[:comment_period])
44
+ ret[:comment_period] &&= CommentPeriond.new(**ret[:comment_period])
43
45
  end
44
46
 
45
47
  # @param ret [Hash]
@@ -54,7 +56,7 @@ module RelatonBipm
54
56
  def dates_hash_to_bib(ret)
55
57
  super
56
58
  ret[:date] &&= ret[:date].map do |d|
57
- BibliographicDate.new d
59
+ BibliographicDate.new **d
58
60
  end
59
61
  end
60
62
 
@@ -62,13 +64,37 @@ module RelatonBipm
62
64
  def relations_hash_to_bib(ret)
63
65
  super
64
66
  ret[:relation] &&= ret[:relation].map do |r|
65
- RelatonBipm::DocumentRelation.new r
67
+ RelatonBipm::DocumentRelation.new **r
66
68
  end
67
69
  end
68
70
 
69
71
  # @param ret [Hash]
70
- def editorialgroup_hash_to_bib(ret)
71
- ret[:editorialgroup] &&= EditorialGroup.new ret[:editorialgroup]
72
+ def editorialgroup_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
73
+ return unless ret[:editorialgroup]
74
+
75
+ cmt = ret[:editorialgroup][:committee].map do |c|
76
+ if (vars = committee_variants c).any?
77
+ content = RelatonBib::LocalizedString.new vars
78
+ Committee.new acronym: c[:acronym], content: content
79
+ else
80
+ Committee.new **c
81
+ end
82
+ end
83
+ wg = array(ret[:editorialgroup][:workgroup]).map do |w|
84
+ w.is_a?(Hash) ? WorkGroup.new(**w) : WorkGroup.new(content: w)
85
+ end
86
+ ret[:editorialgroup] = EditorialGroup.new committee: cmt, workgroup: wg
87
+ end
88
+
89
+ def committee_variants(cmt)
90
+ array(cmt[:variants]).each_with_object([]) do |v, a|
91
+ c = v[:content] || (ac = acronyms[cmt[:acronym]]) && ac[v[:language]]
92
+ a << RelatonBib::LocalizedString.new(c, v[:language], v[:script]) if c
93
+ end
94
+ end
95
+
96
+ def acronyms
97
+ @@acronyms ||= YAML.load_file File.join __dir__, "acronyms.yaml"
72
98
  end
73
99
 
74
100
  # @param ret [Hash]
@@ -28,8 +28,7 @@ module RelatonBipm
28
28
  # @param hash [Hash]
29
29
  # @return [RelatonBipm::BipmBibliographicItem]
30
30
  def hash_to_bib(hash)
31
- item_hash = ::RelatonBipm::HashConverter.hash_to_bib(hash)
32
- ::RelatonBipm::BipmBibliographicItem.new item_hash
31
+ ::RelatonBipm::BipmBibliographicItem.from_hash hash
33
32
  end
34
33
 
35
34
  # Returns hash of XML grammar
@@ -1,3 +1,3 @@
1
1
  module RelatonBipm
2
- VERSION = "1.6.pre1".freeze
2
+ VERSION = "1.7.2".freeze
3
3
  end
@@ -0,0 +1,46 @@
1
+ module RelatonBipm
2
+ class WorkGroup
3
+ # @return [String]
4
+ attr_reader :content
5
+
6
+ # @return [String, nil]
7
+ attr_reader :acronym
8
+
9
+ # @param content [String]
10
+ # @param acronym [String, nil]
11
+ def initialize(content:, acronym: nil)
12
+ @content = content
13
+ @acronym = acronym
14
+ end
15
+
16
+ # @param builder [Nokogiri::XML::Builder]
17
+ def to_xml(builder)
18
+ xml = builder.workgroup content
19
+ xml[:acronym] = acronym if acronym
20
+ end
21
+
22
+ # @param prefix [String]
23
+ # @param count [Integer]
24
+ # @return [String]
25
+ def to_asciibib(prefix, count = 1)
26
+ pref = prefix.empty? ? prefix : prefix + "."
27
+ pref += "workgroup"
28
+ if acronym
29
+ out = count > 1 ? "#{pref}::\n" : ""
30
+ out += "#{pref}.acronym:: #{acronym}\n"
31
+ out + "#{pref}.content:: #{content}\n"
32
+ else "#{pref}:: #{content}\n"
33
+ end
34
+ end
35
+
36
+ # @return [Hash, String]
37
+ def to_hash
38
+ if acronym
39
+ hash = { "content" => content }
40
+ hash["acronym"] = acronym
41
+ hash
42
+ else content
43
+ end
44
+ end
45
+ end
46
+ end
@@ -13,13 +13,14 @@ module RelatonBipm
13
13
 
14
14
  data[:comment_period] = fetch_commentperiond ext
15
15
  data[:si_aspect] = ext.at("si-aspect")&.text
16
+ data[:meeting_note] = ext.at("meeting-note")&.text
16
17
  data
17
18
  end
18
19
 
19
20
  # @param item_hash [Hash]
20
21
  # @return [RelatonBipm::BipmBibliographicItem]
21
22
  def bib_item(item_hash)
22
- BipmBibliographicItem.new item_hash
23
+ BipmBibliographicItem.new **item_hash
23
24
  end
24
25
 
25
26
  # @param item [Nokogiri::XML::Element]
@@ -63,21 +64,41 @@ module RelatonBipm
63
64
 
64
65
  # @param ext [Nokogiri::XML::Element]
65
66
  # @return [RelatonBipm::EditorialGroup, nil]
66
- def fetch_editorialgroup(ext)
67
+ def fetch_editorialgroup(ext) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
67
68
  return unless ext && (eg = ext.at "editorialgroup")
68
69
 
69
- cm = eg.xpath("committee").map &:text
70
- wg = eg.xpath("workgroup").map &:text
70
+ cm = eg.xpath("committee").map do |c|
71
+ vars = variants c
72
+ cnt = if vars.any?
73
+ RelatonBib::LocalizedString.new vars
74
+ else
75
+ RelatonBib::LocalizedString.new c.text, c[:language], c[:script]
76
+ end
77
+ Committee.new acronym: c[:acronym], content: cnt
78
+ end
79
+ wg = eg.xpath("workgroup").map do |w|
80
+ WorkGroup.new content: w.text, acronym: w[:acronym]
81
+ end
71
82
  EditorialGroup.new committee: cm, workgroup: wg
72
83
  end
73
84
 
85
+ # @TODO remove this method before next (1.7.0) relaton release
86
+ # it's in the relaton-bib but hasn't released yet
87
+ # @param title [Nokogiri::XML::Element]
88
+ # @return [Array<RelatonBib::LocalizedString>]
89
+ def variants(elm)
90
+ elm.xpath("variant").map do |v|
91
+ RelatonBib::LocalizedString.new v.text, v[:language], v[:script]
92
+ end
93
+ end
94
+
74
95
  # @param ext [Nokogiri::XML::Element]
75
96
  # @return [RelatonBipm::StructuredIdentifier]
76
97
  def fetch_structuredidentifier(ext)
77
98
  return unless ext && (sid = ext.at("structuredidentifier"))
78
99
 
79
100
  StructuredIdentifier.new(
80
- docnumber: sid.at("docnumber").text, part: sid.at("part")&.text,
101
+ docnumber: sid.at("docnumber")&.text, part: sid.at("part")&.text,
81
102
  appendix: sid.at("appendix")&.text
82
103
  )
83
104
  end
data/relaton_bipm.gemspec CHANGED
@@ -33,15 +33,17 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
33
33
  spec.require_paths = ["lib"]
34
34
 
35
35
  spec.add_development_dependency "byebug"
36
- spec.add_development_dependency "debase"
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
39
  spec.add_development_dependency "rake", "~> 10.0"
40
- spec.add_development_dependency "ruby-debug-ide"
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 "relaton-bib", "~> 1.6.pre"
46
+ spec.add_dependency "mechanize", "~> 2.7.6"
47
+ spec.add_dependency "relaton-bib", "~> 1.7.0"
48
+ spec.add_dependency "serrano", "~> 1.0"
47
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.6.pre1
4
+ version: 1.7.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: 2020-11-12 00:00:00.000000000 Z
11
+ date: 2021-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: debase
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: equivalent-xml
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +67,7 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '10.0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: ruby-debug-ide
70
+ name: ruby-jing
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -95,7 +81,7 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: ruby-jing
84
+ name: simplecov
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
@@ -109,7 +95,7 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: simplecov
98
+ name: vcr
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ">="
@@ -123,7 +109,7 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: vcr
112
+ name: webmock
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - ">="
@@ -137,33 +123,47 @@ dependencies:
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
- name: webmock
126
+ name: mechanize
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
- - - ">="
129
+ - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
131
+ version: 2.7.6
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: '0'
138
+ version: 2.7.6
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: relaton-bib
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: 1.6.pre
145
+ version: 1.7.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.7.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: serrano
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.6.pre
166
+ version: '1.0'
167
167
  description: 'RelatonBipm: retrieve BIPM Standards for bibliographic use using the
168
168
  BibliographicItem model'
169
169
  email:
@@ -172,15 +172,13 @@ executables: []
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
- - ".github/workflows/macos.yml"
176
- - ".github/workflows/ubuntu.yml"
177
- - ".github/workflows/windows.yml"
175
+ - ".github/workflows/rake.yml"
178
176
  - ".gitignore"
179
177
  - ".rspec"
180
178
  - ".rubocop.yml"
181
179
  - Gemfile
182
180
  - LICENSE.txt
183
- - README.md
181
+ - README.adoc
184
182
  - Rakefile
185
183
  - bin/console
186
184
  - bin/rspec
@@ -191,16 +189,19 @@ files:
191
189
  - grammars/isodoc.rng
192
190
  - grammars/reqt.rng
193
191
  - lib/relaton_bipm.rb
192
+ - lib/relaton_bipm/acronyms.yaml
194
193
  - lib/relaton_bipm/bibliographic_date.rb
195
194
  - lib/relaton_bipm/bipm_bibliographic_item.rb
196
195
  - lib/relaton_bipm/bipm_bibliography.rb
197
196
  - lib/relaton_bipm/comment_periond.rb
197
+ - lib/relaton_bipm/committee.rb
198
198
  - lib/relaton_bipm/document_relation.rb
199
199
  - lib/relaton_bipm/editorial_group.rb
200
200
  - lib/relaton_bipm/hash_converter.rb
201
201
  - lib/relaton_bipm/processor.rb
202
202
  - lib/relaton_bipm/structured_identifier.rb
203
203
  - lib/relaton_bipm/version.rb
204
+ - lib/relaton_bipm/workgroup.rb
204
205
  - lib/relaton_bipm/xml_parser.rb
205
206
  - relaton_bipm.gemspec
206
207
  homepage: https://github.com/relaton/relaton-bipm
@@ -220,11 +221,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
221
  version: 2.4.0
221
222
  required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  requirements:
223
- - - ">"
224
+ - - ">="
224
225
  - !ruby/object:Gem::Version
225
- version: 1.3.1
226
+ version: '0'
226
227
  requirements: []
227
- rubygems_version: 3.0.6
228
+ rubygems_version: 3.2.3
228
229
  signing_key:
229
230
  specification_version: 4
230
231
  summary: 'RelatonBipm: retrieve BIPM Standards for bibliographic use using the BibliographicItem