relaton-bib 1.6.0 → 1.7.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: 68c51d5b5aa557ccabc5d856b7409d7d8adcd0b9c78f34dc1a057ca54e72190a
4
- data.tar.gz: f7aba8995fc0ea2021f02956db58e8f3b32525b887e558584036dab471371cda
3
+ metadata.gz: b3035696b10da4bcbf4adf75f8eca150fe15ffa9a729b21f721307d6d4e03c63
4
+ data.tar.gz: 9b43ee47cd051f7cfbff05e14f8a31eaaf0dbce1721e105356a6c215dc22ab40
5
5
  SHA512:
6
- metadata.gz: fbf3250413e9c23af6b001532523f11ba94ecb67e0e913d35d6f79180a9a51f7700becd426d51a948db222b52c7b03fe5e7f643536c134eb78fe95a30e1d157c
7
- data.tar.gz: 31b2762918ff1692d12cc1cfafdd830142a1e79b33d7b172ef18897d7bd9d10e31291a6f1eee1c7a37851dc7bd45e50fceafdee73d8298af6ec3874f34c1be0a
6
+ metadata.gz: e12995f779d549a6e014815b6f4249d7e0528282192c5ef7da6ab40c1bc624278d3ead2f3fedb01bba09d60576424beead0a01e21a6f7e8209362e175e458a2e
7
+ data.tar.gz: 7a7b94d82f2dc38d772dc09da89eacc80c5860e4748b2f240a94dd8f7b7d7a7f949ac4508cdfbfa20f81fb8e1b63c5a61ad959258601717a3aaf0a5957be22d9
@@ -0,0 +1,46 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
+ runs-on: ${{ matrix.os }}
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.7', '2.6', '2.5', '2.4' ]
20
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
21
+ experimental: [ false ]
22
+ include:
23
+ - ruby: '3.0'
24
+ os: 'ubuntu-latest'
25
+ experimental: true
26
+ - ruby: '3.0'
27
+ os: 'windows-latest'
28
+ experimental: true
29
+ - ruby: '3.0'
30
+ os: 'macos-latest'
31
+ experimental: true
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ with:
35
+ submodules: true
36
+
37
+ # https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
38
+ - if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
39
+ run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
40
+
41
+ - uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: ${{ matrix.ruby }}
44
+ bundler-cache: true
45
+
46
+ - run: bundle exec rake
data/grammars/isodoc.rng CHANGED
@@ -24,6 +24,14 @@
24
24
  <start>
25
25
  <ref name="standard-document"/>
26
26
  </start>
27
+ <define name="doctype">
28
+ <element name="doctype">
29
+ <optional>
30
+ <attribute name="abbreviation"/>
31
+ </optional>
32
+ <ref name="DocumentType"/>
33
+ </element>
34
+ </define>
27
35
  <define name="hyperlink">
28
36
  <element name="link">
29
37
  <attribute name="target">
@@ -141,6 +149,11 @@
141
149
  <data type="boolean"/>
142
150
  </attribute>
143
151
  </optional>
152
+ <optional>
153
+ <attribute name="key">
154
+ <data type="boolean"/>
155
+ </attribute>
156
+ </optional>
144
157
  <oneOrMore>
145
158
  <ref name="dt"/>
146
159
  <ref name="dd"/>
@@ -1164,49 +1177,7 @@
1164
1177
  </define>
1165
1178
  <define name="annex">
1166
1179
  <element name="annex">
1167
- <optional>
1168
- <attribute name="id">
1169
- <data type="ID"/>
1170
- </attribute>
1171
- </optional>
1172
- <optional>
1173
- <attribute name="language"/>
1174
- </optional>
1175
- <optional>
1176
- <attribute name="script"/>
1177
- </optional>
1178
- <optional>
1179
- <attribute name="inline-header">
1180
- <data type="boolean"/>
1181
- </attribute>
1182
- </optional>
1183
- <attribute name="obligation">
1184
- <choice>
1185
- <value>normative</value>
1186
- <value>informative</value>
1187
- </choice>
1188
- </attribute>
1189
- <optional>
1190
- <ref name="section-title"/>
1191
- </optional>
1192
- <group>
1193
- <group>
1194
- <zeroOrMore>
1195
- <ref name="BasicBlock"/>
1196
- </zeroOrMore>
1197
- <zeroOrMore>
1198
- <ref name="note"/>
1199
- </zeroOrMore>
1200
- </group>
1201
- <zeroOrMore>
1202
- <choice>
1203
- <ref name="annex-subsection"/>
1204
- <ref name="terms"/>
1205
- <ref name="definitions"/>
1206
- <ref name="references"/>
1207
- </choice>
1208
- </zeroOrMore>
1209
- </group>
1180
+ <ref name="Annex-Section"/>
1210
1181
  </element>
1211
1182
  </define>
1212
1183
  <define name="terms">
data/lib/relaton_bib.rb CHANGED
@@ -15,7 +15,7 @@ module RelatonBib
15
15
  # @param date [String, Integer, Date]
16
16
  # @param str [Boolean]
17
17
  # @return [Date, nil]
18
- def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
18
+ def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
19
19
  return date if date.is_a?(Date)
20
20
 
21
21
  case date.to_s
@@ -62,9 +62,10 @@ module RelatonBib
62
62
  # @return [String]
63
63
  def to_asciibib(prefix = "", count = 1)
64
64
  pref = prefix.empty? ? prefix : prefix + "."
65
- out = count > 1 ? "#{pref}biblionote::\n" : ""
66
- out + "#{pref}biblionote.type:: #{type}\n" if type
67
- out += super "#{pref}biblionote"
65
+ has_attrs = !(type.nil? || type.empty?)
66
+ out = count > 1 && has_attrs ? "#{pref}biblionote::\n" : ""
67
+ out += "#{pref}biblionote.type:: #{type}\n" if type
68
+ out += super "#{pref}biblionote", 1, has_attrs
68
69
  out
69
70
  end
70
71
  end
@@ -31,12 +31,12 @@ module RelatonBib
31
31
  # @return [String, Date, nil]
32
32
  def from(part = nil)
33
33
  d = instance_variable_get "@#{__callee__}".to_sym
34
- return d unless part
34
+ return d unless part && d
35
35
 
36
36
  date = parse_date(d)
37
37
  return date if part == :date
38
38
 
39
- date.send part
39
+ date.is_a?(Date) ? date.send(part) : date
40
40
  end
41
41
 
42
42
  alias_method :to, :from
@@ -87,20 +87,23 @@ module RelatonBib
87
87
  # @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil
88
88
  # @return [String]
89
89
  def date_format(date, format = nil)
90
- case format
91
- when :short then parse_date(date).strftime "%Y-%m"
92
- when :full then parse_date(date).strftime "%Y-%m-%d"
93
- else date
94
- end
90
+ tmplt = case format
91
+ when :short then "%Y-%m"
92
+ when :full then "%Y-%m-%d"
93
+ else return date
94
+ end
95
+ d = parse_date(date)
96
+ d.is_a?(Date) ? d.strftime(tmplt) : d
95
97
  end
96
98
 
97
99
  # @param date [String]
98
100
  # @return [Date]
99
101
  def parse_date(date)
100
102
  case date
101
- when /\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
102
- when /\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
103
- when /\d{4}/ then Date.strptime(date, "%Y") # 2012
103
+ when /^\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
104
+ when /^\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
105
+ when /^\d{4}/ then Date.strptime(date, "%Y") # 2012
106
+ else date
104
107
  end
105
108
  end
106
109
  end
@@ -197,23 +197,23 @@ module RelatonBib
197
197
  @title = TypedTitleStringCollection.new(args[:title])
198
198
 
199
199
  @date = (args[:date] || []).map do |d|
200
- d.is_a?(Hash) ? BibliographicDate.new(d) : d
200
+ d.is_a?(Hash) ? BibliographicDate.new(**d) : d
201
201
  end
202
202
 
203
203
  @contributor = (args[:contributor] || []).map do |c|
204
204
  if c.is_a? Hash
205
- e = c[:entity].is_a?(Hash) ? Organization.new(c[:entity]) : c[:entity]
205
+ e = c[:entity].is_a?(Hash) ? Organization.new(**c[:entity]) : c[:entity]
206
206
  ContributionInfo.new(entity: e, role: c[:role])
207
207
  else c
208
208
  end
209
209
  end
210
210
 
211
211
  @abstract = (args[:abstract] || []).map do |a|
212
- a.is_a?(Hash) ? FormattedString.new(a) : a
212
+ a.is_a?(Hash) ? FormattedString.new(**a) : a
213
213
  end
214
214
 
215
215
  @copyright = args.fetch(:copyright, []).map do |c|
216
- c.is_a?(Hash) ? CopyrightAssociation.new(c) : c
216
+ c.is_a?(Hash) ? CopyrightAssociation.new(**c) : c
217
217
  end
218
218
 
219
219
  @docidentifier = args[:docid] || []
@@ -229,7 +229,7 @@ module RelatonBib
229
229
  @status = args[:docstatus]
230
230
  @relation = DocRelationCollection.new(args[:relation] || [])
231
231
  @link = args.fetch(:link, []).map do |s|
232
- if s.is_a?(Hash) then TypedUri.new(s)
232
+ if s.is_a?(Hash) then TypedUri.new(**s)
233
233
  elsif s.is_a?(String) then TypedUri.new(content: s)
234
234
  else s
235
235
  end
@@ -399,7 +399,7 @@ module RelatonBib
399
399
  # @param type [Symbol] type of url, can be :src/:obp/:rss
400
400
  # @return [String]
401
401
  def url(type = :src)
402
- @link.detect { |s| s.type == type.to_s }.content.to_s
402
+ @link.detect { |s| s.type == type.to_s }&.content&.to_s
403
403
  end
404
404
 
405
405
  def abstract=(value)
@@ -1,4 +1,8 @@
1
- require "bibtex"
1
+ if RUBY_VERSION < "3"
2
+ require "bibtex"
3
+ else
4
+ warn "[relaton-bib] WARNING: BibTex isn't supported with Ruby 3+"
5
+ end
2
6
  require "iso639"
3
7
 
4
8
  module RelatonBib
@@ -101,14 +105,14 @@ module RelatonBib
101
105
  if bibtex["organization"]
102
106
  contributor << {
103
107
  entity: { name: bibtex.organization.to_s },
104
- role: [{ type: "distributor", description: ["sponsor"] }]
108
+ role: [{ type: "distributor", description: ["sponsor"] }],
105
109
  }
106
110
  end
107
111
 
108
112
  if bibtex["school"]
109
113
  contributor << {
110
114
  entity: { name: bibtex.school.to_s },
111
- role: [{ type: "distributor", description: ["sponsor"] }]
115
+ role: [{ type: "distributor", description: ["sponsor"] }],
112
116
  }
113
117
  end
114
118
  contributor
@@ -81,8 +81,11 @@ module RelatonBib
81
81
  attr_reader :entity
82
82
 
83
83
  # @param entity [RelatonBib::Person, RelatonBib::Organization]
84
- # @param role [Array<String>]
85
- def initialize(entity:, role: [{ type: "publisher" }])
84
+ # @param role [Array<Hash>]
85
+ def initialize(entity:, role: [])
86
+ if role.empty?
87
+ role << { type: entity.is_a?(Person) ? "author" : "publisher" }
88
+ end
86
89
  @entity = entity
87
90
  @role = role.map { |r| ContributorRole.new(**r) }
88
91
  end
@@ -30,7 +30,7 @@ module RelatonBib
30
30
  end
31
31
 
32
32
  @owner = owner.map do |o|
33
- o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(o)) : o
33
+ o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(**o)) : o
34
34
  end
35
35
 
36
36
  @from = Date.strptime(from.to_s, "%Y") if from.to_s.match? /\d{4}/
@@ -18,7 +18,7 @@ module RelatonBib
18
18
  # RelatonBib::SourceLocalityStack>] :source_locality
19
19
  # @option relation [RelatonBib::BibliographicItem, NillClass] :bibitem (nil)
20
20
  def initialize(relation)
21
- @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(r) : r }
21
+ @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(**r) : r }
22
22
  end
23
23
 
24
24
  # @todo We don't have replace type anymore. Suppose we should update this
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module RelatonBib
3
4
  # Document status.
4
5
  class DocumentStatus
@@ -54,7 +55,7 @@ module RelatonBib
54
55
  # @return [RelatonBib::DocumentStatus::Stage]
55
56
  def stage_new(stg)
56
57
  if stg.is_a?(Stage) then stg
57
- elsif stg.is_a?(Hash) then Stage.new(stg)
58
+ elsif stg.is_a?(Hash) then Stage.new(**stg)
58
59
  elsif stg.is_a?(String) then Stage.new(value: stg)
59
60
  end
60
61
  end
@@ -44,7 +44,8 @@ module RelatonBib
44
44
  # @param prefix [String]
45
45
  # @param count [Integer] number of elements
46
46
  # @return [String]
47
- def to_asciibib(prefix = "", count = 1)
47
+ def to_asciibib(prefix = "", count = 1, has_attrs = false)
48
+ has_attrs ||= !(format.nil? || format.empty?)
48
49
  pref = prefix.empty? ? prefix : prefix + "."
49
50
  # out = count > 1 ? "#{prefix}::\n" : ""
50
51
  out = super
@@ -97,7 +97,7 @@ module RelatonBib
97
97
  return unless ret[:place]
98
98
 
99
99
  ret[:place] = array(ret[:place]).map do |pl|
100
- pl.is_a?(String) ? Place.new(name: pl) : Place.new(pl)
100
+ pl.is_a?(String) ? Place.new(name: pl) : Place.new(**pl)
101
101
  end
102
102
  end
103
103
 
@@ -120,12 +120,12 @@ module RelatonBib
120
120
  end
121
121
  end
122
122
 
123
- def docid_hash_to_bib(ret)
123
+ def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
124
124
  return unless ret[:docid]
125
125
 
126
126
  ret[:docid] = array(ret[:docid])
127
127
  ret[:docid]&.each_with_index do |id, i|
128
- type = id[:type] || id[:id].match(/^\w+\s/)&.to_s
128
+ type = id[:type] || id[:id].match(/^\w+(?=\s)/)&.to_s
129
129
  ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: type,
130
130
  scope: id[:scope])
131
131
  end
@@ -146,7 +146,7 @@ module RelatonBib
146
146
  ret[:biblionote] = array(ret[:biblionote])
147
147
  .reduce(BiblioNoteCollection.new([])) do |mem, n|
148
148
  mem << if n.is_a?(String) then BiblioNote.new content: n
149
- else BiblioNote.new(n)
149
+ else BiblioNote.new(**n)
150
150
  end
151
151
  end
152
152
  end
@@ -219,7 +219,7 @@ module RelatonBib
219
219
  )
220
220
  end
221
221
 
222
- def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
222
+ def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
223
223
  n = person[:name]
224
224
  FullName.new(
225
225
  forename: array(n[:forename])&.map { |f| localname(f, person) },
@@ -247,10 +247,10 @@ module RelatonBib
247
247
  script: d[:script], format: d[:format] }
248
248
  else { content: d }
249
249
  end
250
- FormattedString.new cnt
250
+ FormattedString.new **cnt
251
251
  end
252
252
  Affiliation.new(
253
- organization: Organization.new(org_hash_to_bib(a[:organization])),
253
+ organization: Organization.new(**org_hash_to_bib(a[:organization])),
254
254
  description: a[:description]
255
255
  )
256
256
  end
@@ -288,7 +288,7 @@ module RelatonBib
288
288
  ret[:relation] = array(ret[:relation])
289
289
  ret[:relation]&.each do |r|
290
290
  if r[:description]
291
- r[:description] = FormattedString.new r[:description]
291
+ r[:description] = FormattedString.new **r[:description]
292
292
  end
293
293
  relation_bibitem_hash_to_bib(r)
294
294
  relation_locality_hash_to_bib(r)
@@ -309,7 +309,7 @@ module RelatonBib
309
309
  # @param item_hash [Hash]
310
310
  # @return [RelatonBib::BibliographicItem]
311
311
  def bib_item(item_hash)
312
- BibliographicItem.new item_hash
312
+ BibliographicItem.new **item_hash
313
313
  end
314
314
 
315
315
  # @param rel [Hash] relation
@@ -356,26 +356,26 @@ module RelatonBib
356
356
  end
357
357
  s[:abbreviation] &&
358
358
  s[:abbreviation] = localizedstring(s[:abbreviation])
359
- Series.new(s)
359
+ Series.new(**s)
360
360
  end
361
361
  end
362
362
 
363
363
  # @param title [Hash]
364
364
  # @return [RelatonBib::TypedTitleString]
365
365
  def typed_title_strig(title)
366
- TypedTitleString.new title
366
+ TypedTitleString.new **title
367
367
  end
368
368
 
369
369
  # @param ret [Hash]
370
370
  def medium_hash_to_bib(ret)
371
- ret[:medium] = Medium.new(ret[:medium]) if ret[:medium]
371
+ ret[:medium] = Medium.new(**ret[:medium]) if ret[:medium]
372
372
  end
373
373
 
374
374
  # @param ret [Hash]
375
375
  def classification_hash_to_bib(ret)
376
376
  if ret[:classification]
377
377
  ret[:classification] = array(ret[:classification]).map do |cls|
378
- Classification.new cls
378
+ Classification.new **cls
379
379
  end
380
380
  end
381
381
  end
@@ -409,7 +409,7 @@ module RelatonBib
409
409
  return unless ret[:editorialgroup]
410
410
 
411
411
  technical_committee = array(ret[:editorialgroup]).map do |wg|
412
- TechnicalCommittee.new WorkGroup.new(wg)
412
+ TechnicalCommittee.new WorkGroup.new(**wg)
413
413
  end
414
414
  ret[:editorialgroup] = EditorialGroup.new technical_committee
415
415
  end
@@ -418,7 +418,7 @@ module RelatonBib
418
418
  def ics_hash_to_bib(ret)
419
419
  return unless ret[:ics]
420
420
 
421
- ret[:ics] = array(ret[:ics]).map { |ics| ICS.new ics }
421
+ ret[:ics] = array(ret[:ics]).map { |ics| ICS.new **ics }
422
422
  end
423
423
 
424
424
  # @param ret [Hash]
@@ -427,7 +427,7 @@ module RelatonBib
427
427
 
428
428
  sids = array(ret[:structuredidentifier]).map do |si|
429
429
  si[:agency] = array si[:agency]
430
- StructuredIdentifier.new si
430
+ StructuredIdentifier.new **si
431
431
  end
432
432
  ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
433
433
  end
@@ -485,7 +485,7 @@ module RelatonBib
485
485
  # @return [RelatonBib::FormattedRef]
486
486
  def formattedref(frf)
487
487
  if frf.is_a?(Hash)
488
- RelatonBib::FormattedRef.new(frf)
488
+ RelatonBib::FormattedRef.new(**frf)
489
489
  else
490
490
  RelatonBib::FormattedRef.new(content: frf)
491
491
  end
@@ -77,9 +77,13 @@ module RelatonBib
77
77
  # @param prefix [String]
78
78
  # @param count [Integer] number of elements
79
79
  # @return [String]
80
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
80
+ def to_asciibib(prefix = "", count = 1, has_attrs = false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
81
81
  pref = prefix.empty? ? prefix : prefix + "."
82
82
  if content.is_a? String
83
+ unless language&.any? || script&.any? || has_attrs
84
+ return "#{prefix}:: #{content}\n"
85
+ end
86
+
83
87
  out = count > 1 ? "#{prefix}::\n" : ""
84
88
  out += "#{pref}content:: #{content}\n"
85
89
  language&.each { |l| out += "#{pref}language:: #{l}\n" }
@@ -82,7 +82,7 @@ module RelatonBib
82
82
  @subdivision = (args[:subdivision] || []).map do |sd|
83
83
  localized_string sd
84
84
  end
85
- @identifier = args.fetch(:identifier, [])
85
+ @identifier = args.fetch(:identifier, [])
86
86
  end
87
87
 
88
88
  # @param opts [Hash]
@@ -8,7 +8,7 @@ module RelatonBib
8
8
  # @param title [Array<RelatonBib::TypedTitleString, Hash>]
9
9
  def initialize(title = [])
10
10
  @array = (title || []).map do |t|
11
- t.is_a?(Hash) ? TypedTitleString.new(t) : t
11
+ t.is_a?(Hash) ? TypedTitleString.new(**t) : t
12
12
  end
13
13
  end
14
14
 
@@ -96,12 +96,12 @@ module RelatonBib
96
96
  fsargs = args.select do |k, _v|
97
97
  %i[content language script format].include? k
98
98
  end
99
- @title = FormattedString.new(fsargs)
99
+ @title = FormattedString.new(**fsargs)
100
100
  end
101
101
  end
102
102
 
103
103
  # @param title [String]
104
- # @return [Array<self>]
104
+ # @return [TypedTitleStringCollection]
105
105
  def self.from_string(title, lang = nil, script = nil)
106
106
  types = %w[title-intro title-main title-part]
107
107
  ttls = split_title(title)
@@ -162,7 +162,7 @@ module RelatonBib
162
162
  pref = prefix.empty? ? prefix : prefix + "."
163
163
  out = count > 1 ? "#{pref}title::\n" : ""
164
164
  out += "#{pref}title.type:: #{type}\n" if type
165
- out += title.to_asciibib "#{pref}title"
165
+ out += title.to_asciibib "#{pref}title", 1, !(type.nil? || type.empty?)
166
166
  out
167
167
  end
168
168
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.6.0".freeze
2
+ VERSION = "1.7.2".freeze
3
3
  end
@@ -177,16 +177,22 @@ module RelatonBib
177
177
  def ttitle(title)
178
178
  return unless title
179
179
 
180
- variants = title.xpath("variant").map do |v|
181
- LocalizedString.new v.text, v[:language], v[:script]
182
- end
183
- content = variants.any? ? variants : title.text
180
+ content = variants(title)
181
+ content = title.text unless content.any?
184
182
  TypedTitleString.new(
185
183
  type: title[:type], content: content, language: title[:language],
186
184
  script: title[:script], format: title[:format]
187
185
  )
188
186
  end
189
187
 
188
+ # @param title [Nokogiri::XML::Element]
189
+ # @return [Array<RelatonBib::LocalizedString>]
190
+ def variants(elm)
191
+ elm.xpath("variant").map do |v|
192
+ LocalizedString.new v.text, v[:language], v[:script]
193
+ end
194
+ end
195
+
190
196
  def fetch_status(item)
191
197
  status = item.at("./status")
192
198
  return unless status
@@ -320,7 +326,7 @@ module RelatonBib
320
326
 
321
327
  # @param item [Nokogiri::XML::Element]
322
328
  # @return [Array<RelatonBib::CopyrightAssociation>]
323
- def fetch_copyright(item)
329
+ def fetch_copyright(item) # rubocop:disable Metrics/AbcSize
324
330
  item.xpath("./copyright").map do |cp|
325
331
  owner = cp.xpath("owner").map do |o|
326
332
  ContributionInfo.new entity: get_org(o.at("organization"))
@@ -370,7 +376,7 @@ module RelatonBib
370
376
  # @param item_hash [Hash]
371
377
  # @return [RelatonBib::BibliographicItem]
372
378
  def bib_item(item_hash)
373
- BibliographicItem.new item_hash
379
+ BibliographicItem.new **item_hash
374
380
  end
375
381
 
376
382
  # @param rel [Nokogiri::XML::Element]
@@ -447,7 +453,7 @@ module RelatonBib
447
453
 
448
454
  # @param ext [Nokogiri::XML::Element]
449
455
  # @return [RelatonBib::StructuredIdentifierCollection]
450
- def fetch_structuredidentifier(ext) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
456
+ def fetch_structuredidentifier(ext) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
451
457
  return unless ext
452
458
 
453
459
  sids = ext.xpath("structuredidentifier").map do |si|
data/relaton-bib.gemspec CHANGED
@@ -24,13 +24,13 @@ Gem::Specification.new do |spec|
24
24
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
25
25
 
26
26
  spec.add_development_dependency "byebug"
27
- spec.add_development_dependency "debase"
27
+ spec.add_development_dependency "debase" if RUBY_VERSION < "3"
28
28
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "ruby-debug-ide"
31
+ spec.add_development_dependency "ruby-debug-ide" if RUBY_VERSION < "3"
32
32
  spec.add_development_dependency "ruby-jing"
33
- spec.add_development_dependency "simplecov"
33
+ spec.add_development_dependency "simplecov" if RUBY_VERSION < "3"
34
34
 
35
35
  spec.add_dependency "addressable"
36
36
  spec.add_dependency "bibtex-ruby"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
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-13 00:00:00.000000000 Z
11
+ date: 2021-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -185,9 +185,7 @@ executables: []
185
185
  extensions: []
186
186
  extra_rdoc_files: []
187
187
  files:
188
- - ".github/workflows/macos.yml"
189
- - ".github/workflows/ubuntu.yml"
190
- - ".github/workflows/windows.yml"
188
+ - ".github/workflows/rake.yml"
191
189
  - ".gitignore"
192
190
  - ".gitmodules"
193
191
  - ".hound.yml"
@@ -1,40 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: macos
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- branches: [ '**' ]
10
-
11
- jobs:
12
- test-macos:
13
- name: Test on Ruby ${{ matrix.ruby }} macOS
14
- runs-on: macos-latest
15
- strategy:
16
- fail-fast: false
17
- matrix:
18
- ruby: [ '2.6', '2.5', '2.4' ]
19
- steps:
20
- - uses: actions/checkout@master
21
- - name: Checkout submodules
22
- shell: bash
23
- run: |
24
- auth_header="$(git config --local --get http.https://github.com/.extraheader)"
25
- git submodule sync --recursive
26
- git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
27
- - name: Use Ruby
28
- uses: actions/setup-ruby@v1
29
- with:
30
- ruby-version: ${{ matrix.ruby }}
31
- architecture: 'x64'
32
- - name: Update gems
33
- run: |
34
- sudo gem install bundler --force
35
- ruby -v | grep 2.5 && bundle config set build.debase --with-cflags="-Wno-error=implicit-function-declaration"
36
- ruby -v | grep 2.5 && bundle config set build.ruby-debug-ide --with-cflags="-Wno-error=implicit-function-declaration"
37
- bundle install --jobs 4 --retry 3
38
- - name: Run specs
39
- run: |
40
- bundle exec rake
@@ -1,39 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: ubuntu
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- branches: [ '**' ]
10
-
11
- jobs:
12
- test-linux:
13
- name: Test on Ruby ${{ matrix.ruby }} Ubuntu
14
- runs-on: ubuntu-latest
15
- strategy:
16
- fail-fast: false
17
- matrix:
18
- ruby: [ '2.6', '2.5', '2.4' ]
19
- steps:
20
- - uses: actions/checkout@master
21
- - name: Checkout submodules
22
- shell: bash
23
- run: |
24
- auth_header="$(git config --local --get http.https://github.com/.extraheader)"
25
- git submodule sync --recursive
26
- git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
27
- - name: Use Ruby
28
- uses: actions/setup-ruby@v1
29
- with:
30
- ruby-version: ${{ matrix.ruby }}
31
- architecture: 'x64'
32
- - name: Update gems
33
- run: |
34
- gem install bundler
35
- bundle install --jobs 4 --retry 3
36
- - name: Run specs
37
- run: |
38
- unset JAVA_TOOL_OPTIONS
39
- bundle exec rake
@@ -1,41 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: windows
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- branches: [ '**' ]
10
-
11
- jobs:
12
- test-windows:
13
- name: Test on Ruby ${{ matrix.ruby }} Windows
14
- runs-on: windows-latest
15
- strategy:
16
- fail-fast: false
17
- matrix:
18
- ruby: [ '2.6', '2.5', '2.4' ]
19
- steps:
20
- - uses: actions/checkout@master
21
- - name: Checkout submodules
22
- shell: bash
23
- run: |
24
- auth_header="$(git config --local --get http.https://github.com/.extraheader)"
25
- git submodule sync --recursive
26
- git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
27
- - name: Use Ruby
28
- uses: actions/setup-ruby@v1
29
- with:
30
- ruby-version: ${{ matrix.ruby }}
31
- architecture: 'x64'
32
- - name: Update gems
33
- shell: pwsh
34
- run: |
35
- gem install bundler
36
- bundle config --local path vendor/bundle
37
- bundle update
38
- bundle install --jobs 4 --retry 3
39
- - name: Run specs
40
- run: |
41
- bundle exec rake