relaton-bib 1.7.5 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,14 @@
1
1
  module RelatonBib
2
2
  class ICS
3
3
  # @return [String]
4
- attr_reader :code, :text
4
+ attr_reader :code
5
+
6
+ # @return [String, nil]
7
+ attr_reader :text
5
8
 
6
9
  # @param code [String]
7
- # @param text [String]
8
- def initialize(code:, text:)
10
+ # @param text [String, nil]
11
+ def initialize(code:, text: nil)
9
12
  @code = code
10
13
  @text = text
11
14
  end
@@ -14,23 +17,25 @@ module RelatonBib
14
17
  def to_xml(builder)
15
18
  builder.ics do |b|
16
19
  b.code code
17
- b.text_ text
20
+ b.text_ text if text
18
21
  end
19
22
  end
20
23
 
21
24
  # @return [Hash]
22
25
  def to_hash
23
- { "code" => code, "text" => text }
26
+ hash = { "code" => code }
27
+ hash["text"] = text if text
28
+ hash
24
29
  end
25
30
 
26
31
  # @param prefix [String]
27
32
  # @param count [Integer] number of ics
28
33
  # @return [String]
29
34
  def to_asciibib(prefix = "", count = 1)
30
- pref = prefix.empty? ? "ics" : prefix + ".ics"
35
+ pref = prefix.empty? ? "ics" : "#{prefix}.ics"
31
36
  out = count > 1 ? "#{pref}::\n" : ""
32
37
  out += "#{pref}.code:: #{code}\n"
33
- out += "#{pref}.text:: #{text}\n"
38
+ out += "#{pref}.text:: #{text}\n" if text
34
39
  out
35
40
  end
36
41
  end
@@ -18,12 +18,8 @@ module RelatonBib
18
18
  # @param language [String] language code Iso639
19
19
  # @param script [String] script code Iso15924
20
20
  def initialize(content, language = nil, script = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
21
- if content.is_a? Array
22
- inv = content.reject { |c| c.is_a?(LocalizedString) || c.is_a?(Hash) }
23
- end
24
- unless content.is_a?(String) || inv&.none? && content.any?
25
- klass = content.is_a?(Array) ? inv.first.class : content.class
26
- raise ArgumentError, "invalid LocalizedString content type: #{klass}"
21
+ if content.is_a?(Array) && content.none?
22
+ raise ArgumentError, "LocalizedString content is empty"
27
23
  end
28
24
  @language = language.is_a?(String) ? [language] : language
29
25
  @script = script.is_a?(String) ? [script] : script
@@ -31,6 +27,8 @@ module RelatonBib
31
27
  content.map do |c|
32
28
  if c.is_a?(Hash)
33
29
  LocalizedString.new c[:content], c[:language], c[:script]
30
+ elsif c.is_a?(String)
31
+ LocalizedString.new c
34
32
  else c
35
33
  end
36
34
  end
@@ -5,8 +5,8 @@ require "relaton_bib/contributor"
5
5
  module RelatonBib
6
6
  # Organization identifier.
7
7
  class OrgIdentifier
8
- ORCID = "orcid"
9
- URI = "uri"
8
+ # ORCID = "orcid"
9
+ # URI = "uri"
10
10
 
11
11
  # @return [String]
12
12
  attr_reader :type
@@ -14,12 +14,12 @@ module RelatonBib
14
14
  # @return [String]
15
15
  attr_reader :value
16
16
 
17
- # @param type [String] "orcid" or "uri"
17
+ # @param type [String]
18
18
  # @param value [String]
19
19
  def initialize(type, value)
20
- unless [ORCID, URI].include? type
21
- raise ArgumentError, 'Invalid type. It should be "orsid" or "uri".'
22
- end
20
+ # unless [ORCID, URI].include? type
21
+ # raise ArgumentError, 'Invalid type. It should be "orsid" or "uri".'
22
+ # end
23
23
 
24
24
  @type = type
25
25
  @value = value
@@ -40,7 +40,7 @@ module RelatonBib
40
40
  # @return [String]
41
41
  def to_asciibib(prefix = "", count = 1)
42
42
  pref = prefix.empty? ? prefix : prefix + "."
43
- out = count > 1 ? "#{pref}identifier::\m" : ""
43
+ out = count > 1 ? "#{pref}identifier::\n" : ""
44
44
  out += "#{pref}identifier.type:: #{type}\n"
45
45
  out += "#{pref}identifier.value:: #{value}\n"
46
46
  out
@@ -119,7 +119,7 @@ module RelatonBib
119
119
  # @return [String]
120
120
  def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
121
121
  pref = prefix.sub /\*$/, "organization"
122
- out = count > 1 ? "#{pref}::\m" : ""
122
+ out = count > 1 ? "#{pref}::\n" : ""
123
123
  name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
124
124
  out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
125
125
  subdivision.each do |sd|
@@ -102,15 +102,17 @@ module RelatonBib
102
102
 
103
103
  # Person identifier type.
104
104
  module PersonIdentifierType
105
- ISNI = "isni"
106
- URI = "uri"
105
+ ISNI = "isni"
106
+ ORCID = "orcid"
107
+ URI = "uri"
107
108
 
108
109
  # Checks type.
109
110
  # @param type [String]
110
111
  # @raise [ArgumentError] if type isn't "isni" or "uri"
111
112
  def self.check(type)
112
- unless [ISNI, URI].include? type
113
- raise ArgumentError, 'Invalid type. It should be "isni" or "uri".'
113
+ unless [ISNI, ORCID, URI].include? type
114
+ raise ArgumentError, 'Invalid type. It should be "isni", "orcid", "\
115
+ "or "uri".'
114
116
  end
115
117
  end
116
118
  end
@@ -118,6 +120,7 @@ module RelatonBib
118
120
  # Person identifier.
119
121
  class PersonIdentifier
120
122
  # @return [RelatonBib::PersonIdentifierType::ISNI,
123
+ # RelatonBib::PersonIdentifierType::ORCID,
121
124
  # RelatonBib::PersonIdentifierType::URI]
122
125
  attr_accessor :type
123
126
 
@@ -125,6 +128,7 @@ module RelatonBib
125
128
  attr_accessor :value
126
129
 
127
130
  # @param type [RelatonBib::PersonIdentifierType::ISNI,
131
+ # RelatonBib::PersonIdentifierType::ORCID,
128
132
  # RelatonBib::PersonIdentifierType::URI]
129
133
  # @param value [String]
130
134
  def initialize(type, value)
@@ -5,7 +5,7 @@ module RelatonBib
5
5
  # Series class.
6
6
  #
7
7
  class Series
8
- TYPES = %w[main alt].freeze
8
+ # TYPES = %w[main alt].freeze
9
9
 
10
10
  # @return [String, NilClass] allowed values: "main" or "alt"
11
11
  attr_reader :type
@@ -56,9 +56,9 @@ module RelatonBib
56
56
  raise ArgumentError, "argument `title` or `formattedref` should present"
57
57
  end
58
58
 
59
- if args[:type] && !TYPES.include?(args[:type])
60
- warn "[relaton-bib] Series type is invalid: #{args[:type]}"
61
- end
59
+ # if args[:type] && !TYPES.include?(args[:type])
60
+ # warn "[relaton-bib] Series type is invalid: #{args[:type]}"
61
+ # end
62
62
 
63
63
  @type = args[:type] # if %w[main alt].include? args[:type]
64
64
  @title = args[:title]
@@ -10,7 +10,7 @@ module RelatonBib
10
10
 
11
11
  # @param type [String, NilClass] src/obp/rss
12
12
  # @param content [String]
13
- def initialize(type: nil, content:)
13
+ def initialize(content:, type: nil)
14
14
  @type = type
15
15
  @content = Addressable::URI.parse content if content
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.7.5".freeze
2
+ VERSION = "1.9.0".freeze
3
3
  end
@@ -1,45 +1,57 @@
1
1
  module RelatonBib
2
2
  class WorkGroup
3
3
  # @return [String]
4
- attr_reader :content
4
+ attr_reader :name
5
5
 
6
6
  # @return [Integer, nil]
7
7
  attr_reader :number
8
8
 
9
9
  # @return [String, nil]
10
- attr_reader :type
10
+ attr_reader :identifier, :prefix, :type
11
11
 
12
- # @param content [String]
12
+ # @param name [String]
13
+ # @param identifier [String, nil]
14
+ # @param prefix [String, nil]
13
15
  # @param number [Integer, nil]
14
16
  # @param type [String, nil]
15
- def initialize(content:, number: nil, type: nil)
16
- @content = content
17
+ def initialize(name:, identifier: nil, prefix: nil, number: nil, type: nil)
18
+ @identifier = identifier
19
+ @prefix = prefix
20
+ @name = name
17
21
  @number = number
18
22
  @type = type
19
23
  end
20
24
 
21
25
  # @param builder [Nokogiri::XML::Builder]
22
- def to_xml(builder)
23
- builder.text content
26
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize
27
+ builder.text name
24
28
  builder.parent[:number] = number if number
25
29
  builder.parent[:type] = type if type
30
+ builder.parent[:identifier] = identifier if identifier
31
+ builder.parent[:prefix] = prefix if prefix
26
32
  end
27
33
 
28
34
  # @return [Hash]
29
35
  def to_hash
30
- hash = { "content" => content }
36
+ hash = { "name" => name }
31
37
  hash["number"] = number if number
32
38
  hash["type"] = type if type
39
+ hash["identifier"] = identifier if identifier
40
+ hash["prefix"] = prefix if prefix
33
41
  hash
34
42
  end
35
43
 
36
- # @param prefix [String]
44
+ # @param prfx [String]
45
+ # @param count [Integer]
37
46
  # @return [String]
38
- def to_asciibib(prefix = "")
39
- pref = prefix.empty? ? prefix : prefix + "."
40
- out = "#{pref}content:: #{content}\n"
47
+ def to_asciibib(prfx = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity
48
+ pref = prfx.empty? ? prfx : "#{prfx}."
49
+ out = count > 1 ? "#{pref}::\n" : ""
50
+ out += "#{pref}name:: #{name}\n"
41
51
  out += "#{pref}number:: #{number}\n" if number
42
52
  out += "#{pref}type:: #{type}\n" if type
53
+ out += "#{pref}identifier:: #{identifier}\n" if identifier
54
+ out += "#{pref}prefix:: #{prefix}\n" if prefix
43
55
  out
44
56
  end
45
57
  end
@@ -52,6 +52,7 @@ module RelatonBib
52
52
  license: bibitem.xpath("license").map(&:text),
53
53
  validity: fetch_validity(bibitem),
54
54
  doctype: ext&.at("doctype")&.text,
55
+ subdoctype: ext&.at("subdoctype")&.text,
55
56
  editorialgroup: fetch_editorialgroup(ext),
56
57
  ics: fetch_ics(ext),
57
58
  structuredidentifier: fetch_structuredidentifier(ext),
@@ -81,7 +82,7 @@ module RelatonBib
81
82
  type: n[:type],
82
83
  format: n[:format],
83
84
  language: n[:language],
84
- script: n[:script]
85
+ script: n[:script],
85
86
  )
86
87
  end
87
88
  BiblioNoteCollection.new bnotes
@@ -201,7 +202,7 @@ module RelatonBib
201
202
  DocumentStatus.new(
202
203
  stage: stg ? stage(stg) : status.text,
203
204
  substage: stage(status.at("substage")),
204
- iteration: status.at("iteration")&.text
205
+ iteration: status.at("iteration")&.text,
205
206
  )
206
207
  end
207
208
 
@@ -262,7 +263,7 @@ module RelatonBib
262
263
  city: c.at("./city")&.text,
263
264
  state: c.at("./state")&.text,
264
265
  country: c.at("./country")&.text,
265
- postcode: c.at("./postcode")&.text
266
+ postcode: c.at("./postcode")&.text,
266
267
  )
267
268
  else
268
269
  Contact.new(type: c.name, value: c.text)
@@ -290,7 +291,7 @@ module RelatonBib
290
291
  name: name,
291
292
  affiliation: affiliations,
292
293
  contact: contact,
293
- identifier: identifier
294
+ identifier: identifier,
294
295
  )
295
296
  end
296
297
 
@@ -358,7 +359,7 @@ module RelatonBib
358
359
  description: relation_description(rel),
359
360
  bibitem: bib_item(item_data(rel.at("./bibitem"))),
360
361
  locality: localities(rel),
361
- source_locality: source_localities(rel)
362
+ source_locality: source_localities(rel),
362
363
  )
363
364
  end
364
365
  end
@@ -376,7 +377,7 @@ module RelatonBib
376
377
  # @param item_hash [Hash]
377
378
  # @return [RelatonBib::BibliographicItem]
378
379
  def bib_item(item_hash)
379
- BibliographicItem.new **item_hash
380
+ BibliographicItem.new(**item_hash)
380
381
  end
381
382
 
382
383
  # @param rel [Nokogiri::XML::Element]
@@ -398,7 +399,7 @@ module RelatonBib
398
399
  klass.new(
399
400
  loc[:type],
400
401
  LocalizedString.new(loc.at("./referenceFrom").text),
401
- ref_to
402
+ ref_to,
402
403
  )
403
404
  end
404
405
 
@@ -436,8 +437,10 @@ module RelatonBib
436
437
  return unless ext && (eg = ext.at "editorialgroup")
437
438
 
438
439
  eg = eg.xpath("technical-committee").map do |tc|
439
- wg = WorkGroup.new(content: tc.text, number: tc[:number]&.to_i,
440
- type: tc[:type])
440
+ wg = WorkGroup.new(
441
+ name: tc.text, number: tc[:number]&.to_i, type: tc[:type],
442
+ identifier: tc[:identifier], prefix: tc[:prefix]
443
+ )
441
444
  TechnicalCommittee.new wg
442
445
  end
443
446
  EditorialGroup.new eg if eg.any?
@@ -468,7 +471,7 @@ module RelatonBib
468
471
  supplementtype: si.at("supplementtype")&.text,
469
472
  supplementnumber: si.at("supplementnumber")&.text,
470
473
  language: si.at("language")&.text,
471
- year: si.at("year")&.text
474
+ year: si.at("year")&.text,
472
475
  )
473
476
  end
474
477
  StructuredIdentifierCollection.new sids
data/lib/relaton_bib.rb CHANGED
@@ -39,11 +39,11 @@ module RelatonBib
39
39
 
40
40
  # @param array [Array]
41
41
  # @return [Array<String>, String]
42
- def single_element_array(array) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
42
+ def single_element_array(array)
43
43
  if array.size > 1
44
44
  array.map { |e| e.is_a?(String) ? e : e.to_hash }
45
45
  else
46
- array.first&.is_a?(String) ? array[0] : array.first&.to_hash
46
+ array.first.is_a?(String) ? array[0] : array.first&.to_hash
47
47
  end
48
48
  end
49
49
  end
data/relaton-bib.gemspec CHANGED
@@ -21,14 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
24
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
25
25
 
26
26
  spec.add_development_dependency "byebug"
27
- # ec.add_development_dependency "debase"
28
27
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
29
28
  spec.add_development_dependency "rake", "~> 13.0"
30
29
  spec.add_development_dependency "rspec", "~> 3.0"
31
- # spec.add_development_dependency "ruby-debug-ide"
32
30
  spec.add_development_dependency "ruby-jing"
33
31
  spec.add_development_dependency "simplecov"
34
32
 
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.7.5
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-04-19 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
@@ -226,14 +226,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - ">="
228
228
  - !ruby/object:Gem::Version
229
- version: 2.4.0
229
+ version: 2.5.0
230
230
  required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  requirements:
232
232
  - - ">="
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
- rubygems_version: 3.0.6
236
+ rubygems_version: 3.2.3
237
237
  signing_key:
238
238
  specification_version: 4
239
239
  summary: 'RelatonBib: Ruby XMLDOC impementation.'