relaton-bib 1.2.2 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +1 -0
  3. data/.rubocop.yml +2 -2
  4. data/README.adoc +60 -18
  5. data/grammars/isodoc.rng +130 -21
  6. data/grammars/reqt.rng +2 -8
  7. data/lib/relaton_bib.rb +15 -15
  8. data/lib/relaton_bib/bib_item_locality.rb +13 -1
  9. data/lib/relaton_bib/biblio_note.rb +11 -0
  10. data/lib/relaton_bib/biblio_version.rb +12 -0
  11. data/lib/relaton_bib/bibliographic_date.rb +15 -1
  12. data/lib/relaton_bib/bibliographic_item.rb +93 -25
  13. data/lib/relaton_bib/classification.rb +11 -0
  14. data/lib/relaton_bib/contribution_info.rb +27 -1
  15. data/lib/relaton_bib/contributor.rb +55 -1
  16. data/lib/relaton_bib/copyright_association.rb +14 -1
  17. data/lib/relaton_bib/document_identifier.rb +49 -9
  18. data/lib/relaton_bib/document_relation.rb +14 -4
  19. data/lib/relaton_bib/document_relation_collection.rb +12 -0
  20. data/lib/relaton_bib/document_status.rb +10 -0
  21. data/lib/relaton_bib/editorial_group.rb +14 -0
  22. data/lib/relaton_bib/formatted_ref.rb +7 -0
  23. data/lib/relaton_bib/formatted_string.rb +11 -0
  24. data/lib/relaton_bib/hash_converter.rb +55 -36
  25. data/lib/relaton_bib/ics.rb +11 -0
  26. data/lib/relaton_bib/localized_string.rb +23 -6
  27. data/lib/relaton_bib/medium.rb +11 -0
  28. data/lib/relaton_bib/organization.rb +27 -7
  29. data/lib/relaton_bib/person.rb +54 -7
  30. data/lib/relaton_bib/place.rb +14 -2
  31. data/lib/relaton_bib/series.rb +25 -4
  32. data/lib/relaton_bib/structured_identifier.rb +30 -0
  33. data/lib/relaton_bib/technical_committee.rb +11 -0
  34. data/lib/relaton_bib/typed_title_string.rb +13 -7
  35. data/lib/relaton_bib/typed_uri.rb +11 -0
  36. data/lib/relaton_bib/validity.rb +11 -0
  37. data/lib/relaton_bib/version.rb +1 -1
  38. data/lib/relaton_bib/workgroup.rb +10 -0
  39. data/lib/relaton_bib/xml_parser.rb +55 -38
  40. metadata +5 -5
@@ -22,5 +22,16 @@ module RelatonBib
22
22
  def to_hash
23
23
  { "code" => code, "text" => text }
24
24
  end
25
+
26
+ # @param prefix [String]
27
+ # @param count [Integer] number of ics
28
+ # @return [String]
29
+ def to_asciibib(prefix = "", count = 1)
30
+ pref = prefix.empty? ? "ics" : prefix + ".ics"
31
+ out = count > 1 ? "#{pref}::\n" : ""
32
+ out += "#{pref}.code:: #{code}\n"
33
+ out += "#{pref}.text:: #{text}\n"
34
+ out
35
+ end
25
36
  end
26
37
  end
@@ -17,10 +17,11 @@ module RelatonBib
17
17
  # @param content [String, Array<RelatonBib::LocalizedString>]
18
18
  # @param language [String] language code Iso639
19
19
  # @param script [String] script code Iso15924
20
- def initialize(content, language = nil, script = nil)
21
- unless content.is_a?(String) || content.is_a?(Array) &&
22
- (inv = content.reject { |c| c.is_a?(LocalizedString) || c.is_a?(Hash) }).
23
- none? && content.any?
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?
24
25
  klass = content.is_a?(Array) ? inv.first.class : content.class
25
26
  raise ArgumentError, "invalid LocalizedString content type: #{klass}"
26
27
  end
@@ -48,7 +49,7 @@ module RelatonBib
48
49
  end
49
50
 
50
51
  # @param builder [Nokogiri::XML::Builder]
51
- def to_xml(builder)
52
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
52
53
  return unless content
53
54
 
54
55
  if content.is_a?(Array)
@@ -61,7 +62,7 @@ module RelatonBib
61
62
  end
62
63
 
63
64
  # @return [Hash]
64
- def to_hash
65
+ def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
65
66
  if content.is_a? String
66
67
  return content unless language || script
67
68
 
@@ -72,5 +73,21 @@ module RelatonBib
72
73
  else content.map &:to_hash
73
74
  end
74
75
  end
76
+
77
+ # @param prefix [String]
78
+ # @param count [Integer] number of elements
79
+ # @return [String]
80
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
81
+ pref = prefix.empty? ? prefix : prefix + "."
82
+ if content.is_a? String
83
+ out = count > 1 ? "#{prefix}::\n" : ""
84
+ out += "#{pref}content:: #{content}\n"
85
+ language&.each { |l| out += "#{pref}language:: #{l}\n" }
86
+ script&.each { |s| out += "#{pref}script:: #{s}\n" }
87
+ out
88
+ else
89
+ content.map { |c| c.to_asciibib "#{pref}variant", content.size }.join
90
+ end
91
+ end
75
92
  end
76
93
  end
@@ -29,5 +29,16 @@ module RelatonBib
29
29
  hash["scale"] = scale if scale
30
30
  hash
31
31
  end
32
+
33
+ # @param prefix [String]
34
+ # @return [String]
35
+ def to_asciibib(prefix = "")
36
+ pref = prefix.empty? ? "medium." : prefix + ".medium."
37
+ out = ""
38
+ out += "#{pref}form:: #{form}\n" if form
39
+ out += "#{pref}size:: #{size}\n" if size
40
+ out += "#{pref}scale:: #{scale}\n" if scale
41
+ out
42
+ end
32
43
  end
33
44
  end
@@ -3,11 +3,6 @@
3
3
  require "relaton_bib/contributor"
4
4
 
5
5
  module RelatonBib
6
- # module OrgIdentifierType
7
- # ORCID = 'orcid'
8
- # URI = 'uri'
9
- # end
10
-
11
6
  # Organization identifier.
12
7
  class OrgIdentifier
13
8
  ORCID = "orcid"
@@ -39,6 +34,17 @@ module RelatonBib
39
34
  def to_hash
40
35
  { "type" => type, "id" => value }
41
36
  end
37
+
38
+ # @param prefix [String]
39
+ # @param count [Integer]
40
+ # @return [String]
41
+ def to_asciibib(prefix = "", count = 1)
42
+ pref = prefix.empty? ? prefix : prefix + "."
43
+ out = count > 1 ? "#{pref}identifier::\m" : ""
44
+ out += "#{pref}identifier.type:: #{type}\n"
45
+ out += "#{pref}identifier.value:: #{value}\n"
46
+ out
47
+ end
42
48
  end
43
49
 
44
50
  # Organization.
@@ -61,7 +67,7 @@ module RelatonBib
61
67
  # @param url [String]
62
68
  # @param identifier [Array<RelatonBib::OrgIdentifier>]
63
69
  # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
64
- def initialize(**args)
70
+ def initialize(**args) # rubocop:disable Metrics/AbcSize
65
71
  raise ArgumentError, "missing keyword: name" unless args[:name]
66
72
 
67
73
  super(url: args[:url], contact: args.fetch(:contact, []))
@@ -78,7 +84,7 @@ module RelatonBib
78
84
  end
79
85
 
80
86
  # @param builder [Nokogiri::XML::Builder]
81
- def to_xml(builder)
87
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize
82
88
  builder.organization do
83
89
  name.each do |n|
84
90
  builder.name { |b| n.to_xml b }
@@ -100,6 +106,20 @@ module RelatonBib
100
106
  { "organization" => hash.merge(super) }
101
107
  end
102
108
 
109
+ # @param prefix [String]
110
+ # @param count [Integer]
111
+ # @return [String]
112
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
113
+ pref = prefix.sub /\*$/, "organization"
114
+ out = count > 1 ? "#{pref}::\m" : ""
115
+ name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
116
+ out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
117
+ out += subdivision.to_asciibib "#{pref}.subdivision" if subdivision
118
+ identifier.each { |n| out += n.to_asciibib pref, identifier.size }
119
+ out += super pref
120
+ out
121
+ end
122
+
103
123
  private
104
124
 
105
125
  # @param arg [String, Hash, RelatoBib::LocalizedString]
@@ -45,12 +45,12 @@ module RelatonBib
45
45
  end
46
46
 
47
47
  # @param builder [Nokogiri::XML::Builder]
48
- def to_xml(builder)
48
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
49
49
  builder.name do
50
50
  if completename
51
51
  builder.completename { completename.to_xml builder }
52
52
  else
53
- prefix.each { |p| builder.prefix { p.to_xml builder } }
53
+ prefix.each { |p| builder.prefix { p.to_xml builder } }
54
54
  forename.each { |f| builder.forename { f.to_xml builder } }
55
55
  initial.each { |i| builder.initial { i.to_xml builder } }
56
56
  builder.surname { surname.to_xml builder }
@@ -60,7 +60,7 @@ module RelatonBib
60
60
  end
61
61
 
62
62
  # @return [Hash]
63
- def to_hash
63
+ def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
64
64
  hash = {}
65
65
  hash["forename"] = single_element_array(forename) if forename&.any?
66
66
  hash["initial"] = single_element_array(initial) if initial&.any?
@@ -70,6 +70,24 @@ module RelatonBib
70
70
  hash["completename"] = completename.to_hash if completename
71
71
  hash
72
72
  end
73
+
74
+ # @param pref [String]
75
+ # @return [String]
76
+ def to_asciibib(pref) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
77
+ prf = pref.empty? ? pref : pref + "."
78
+ prf += "name."
79
+ out = forename.map do |fn|
80
+ fn.to_asciibib "#{prf}forename", forename.size
81
+ end.join
82
+ initial.each { |i| out += i.to_asciibib "#{prf}initial", initial.size }
83
+ out += surname.to_asciibib "#{prf}surname" if surname
84
+ addition.each do |ad|
85
+ out += ad.to_asciibib "#{prf}addition", addition.size
86
+ end
87
+ prefix.each { |pr| out += pr.to_asciibib "#{prf}prefix", prefix.size }
88
+ out += completename.to_asciibib "#{prf}completename" if completename
89
+ out
90
+ end
73
91
  end
74
92
 
75
93
  # Person identifier type.
@@ -89,13 +107,15 @@ module RelatonBib
89
107
 
90
108
  # Person identifier.
91
109
  class PersonIdentifier
92
- # @return [RelatonBib::PersonIdentifierType::ISNI, RelatonBib::PersonIdentifierType::URI]
110
+ # @return [RelatonBib::PersonIdentifierType::ISNI,
111
+ # RelatonBib::PersonIdentifierType::URI]
93
112
  attr_accessor :type
94
113
 
95
114
  # @return [String]
96
115
  attr_accessor :value
97
116
 
98
- # @param type [RelatonBib::PersonIdentifierType::ISNI, RelatonBib::PersonIdentifierType::URI]
117
+ # @param type [RelatonBib::PersonIdentifierType::ISNI,
118
+ # RelatonBib::PersonIdentifierType::URI]
99
119
  # @param value [String]
100
120
  def initialize(type, value)
101
121
  PersonIdentifierType.check type
@@ -113,6 +133,17 @@ module RelatonBib
113
133
  def to_hash
114
134
  { "type" => type, "id" => value }
115
135
  end
136
+
137
+ # @param prefix [String]
138
+ # @param count [Integer] number of ids
139
+ # @return [String]
140
+ def to_asciibib(prefix = "", count = 1)
141
+ pref = prefix.empty? ? prefix : prefix + "."
142
+ out = count > 1 ? "#{prefix}::\n" : ""
143
+ out += "#{pref}type:: #{type}\n"
144
+ out += "#{pref}value:: #{value}\n"
145
+ out
146
+ end
116
147
  end
117
148
 
118
149
  # Person class.
@@ -131,7 +162,8 @@ module RelatonBib
131
162
  # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
132
163
  # @param identifier [Array<RelatonBib::PersonIdentifier>]
133
164
  # @param url [String, NilClass]
134
- def initialize(name:, affiliation: [], contact: [], identifier: [], url: nil)
165
+ def initialize(name:, affiliation: [], contact: [], identifier: [],
166
+ url: nil)
135
167
  super(contact: contact, url: url)
136
168
  @name = name
137
169
  @affiliation = affiliation
@@ -151,9 +183,24 @@ module RelatonBib
151
183
  # @return [Hash]
152
184
  def to_hash
153
185
  hash = { "name" => name.to_hash }
154
- hash["affiliation"] = single_element_array(affiliation) if affiliation&.any?
186
+ if affiliation&.any?
187
+ hash["affiliation"] = single_element_array(affiliation)
188
+ end
155
189
  hash["identifier"] = single_element_array(identifier) if identifier&.any?
156
190
  { "person" => hash.merge(super) }
157
191
  end
192
+
193
+ # @param prefix [String]
194
+ # @count [Integer] number of persons
195
+ # @return [String]
196
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
197
+ pref = prefix.sub /\*$/, "person"
198
+ out = count > 1 ? "#{pref}::\n" : ""
199
+ out += name.to_asciibib pref
200
+ affiliation.each { |af| out += af.to_asciibib pref, affiliation.size }
201
+ identifier.each { |id| out += id.to_asciibib pref, identifier.size }
202
+ out += super pref
203
+ out
204
+ end
158
205
  end
159
206
  end
@@ -25,7 +25,7 @@ module RelatonBib
25
25
  # @return [Hash]
26
26
  def to_hash
27
27
  if uri || region
28
- hash = { name: name }
28
+ hash = { "name" => name }
29
29
  hash["uri"] = uri if uri
30
30
  hash["region"] = region if region
31
31
  hash
@@ -33,5 +33,17 @@ module RelatonBib
33
33
  name
34
34
  end
35
35
  end
36
+
37
+ # @param prefix [String]
38
+ # @param count [Integer] number of places
39
+ # @return [Stirng]
40
+ def to_asciibib(prefix = "", count = 1)
41
+ pref = prefix.empty? ? "place" : prefix + ".place"
42
+ out = count > 1 ? "#{pref}::\n" : ""
43
+ out += "#{pref}.name:: #{name}\n"
44
+ out += "#{pref}.uri:: #{uri}\n" if uri
45
+ out += "#{pref}.region:: #{region}\n" if region
46
+ out
47
+ end
36
48
  end
37
- end
49
+ end
@@ -39,7 +39,8 @@ module RelatonBib
39
39
 
40
40
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
41
 
42
- # @param type [String, NilClass] title or formattedref argument should be passed
42
+ # @param type [String, NilClass] title or formattedref argument should be
43
+ # passed
43
44
  # @param formattedref [RelatonBib::FormattedRef, NilClass]
44
45
  # @param title [RelatonBib::TypedTitleString, NilClass]
45
46
  # @param place [String, NilClass]
@@ -50,7 +51,8 @@ module RelatonBib
50
51
  # @param number [String, NilClass]
51
52
  # @param partnumber [String, NilClass]
52
53
  def initialize(**args)
53
- unless args[:title].is_a?(RelatonBib::TypedTitleString) || args[:formattedref]
54
+ unless args[:title].is_a?(RelatonBib::TypedTitleString) ||
55
+ args[:formattedref]
54
56
  raise ArgumentError, "argument `title` or `formattedref` should present"
55
57
  end
56
58
 
@@ -74,7 +76,7 @@ module RelatonBib
74
76
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
75
77
 
76
78
  # @param builder [Nokogiri::XML::Builder]
77
- def to_xml(builder)
79
+ def to_xml(builder) # rubocop:disable Metrics/MethodLength
78
80
  xml = builder.series do
79
81
  if formattedref
80
82
  formattedref.to_xml builder
@@ -95,7 +97,7 @@ module RelatonBib
95
97
  # rubocop:enable Metrics/PerceivedComplexity
96
98
 
97
99
  # @return [Hash]
98
- def to_hash
100
+ def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
99
101
  hash = {}
100
102
  hash["type"] = type if type
101
103
  hash["formattedref"] = formattedref.to_hash if formattedref
@@ -109,5 +111,24 @@ module RelatonBib
109
111
  hash["partnumber"] = partnumber if partnumber
110
112
  hash
111
113
  end
114
+
115
+ # @param prefix [String]
116
+ # @param count [Integer]
117
+ # @return [String]
118
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
119
+ pref = prefix.empty? ? "series" : prefix + ".series"
120
+ out = count > 1 ? "#{pref}::\n" : ""
121
+ out += "#{pref}.type:: #{type}\n" if type
122
+ out += formattedref.to_asciibib pref if formattedref
123
+ out += title.to_asciibib pref if title
124
+ out += "#{pref}.place:: #{place}\n" if place
125
+ out += "#{pref}.organization:: #{organization}\n" if organization
126
+ out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
127
+ out += "#{pref}.from:: #{from}\n" if from
128
+ out += "#{pref}.to:: #{to}\n" if to
129
+ out += "#{pref}.number:: #{number}\n" if number
130
+ out += "#{pref}.partnumber:: #{partnumber}\n" if partnumber
131
+ out
132
+ end
112
133
  end
113
134
  end
@@ -20,6 +20,17 @@ module RelatonBib
20
20
  single_element_array @collection
21
21
  end
22
22
 
23
+ # @param prefix [String]
24
+ # @return [String]
25
+ def to_asciibib(prefix = "")
26
+ pref = prefix.empty? ? prefix : prefix + "."
27
+ pref += "structured_identifier"
28
+ @collection.reduce("") do |out, si|
29
+ out += "#{pref}::\n" if @collection.size > 1
30
+ out + si.to_asciibib(pref)
31
+ end
32
+ end
33
+
23
34
  # remoe year from docnumber
24
35
  def remove_date
25
36
  @collection.each &:remove_date
@@ -119,6 +130,25 @@ module RelatonBib
119
130
  end
120
131
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
121
132
 
133
+ # @param prefix [String]
134
+ # @return [String]
135
+ def to_asciibib(prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
136
+ out = "#{prefix}.docnumber:: #{docnumber}\n"
137
+ agency.each { |a| out += "#{prefix}.agency:: #{a}\n" }
138
+ out += "#{prefix}.type:: #{type}\n" if type
139
+ out += "#{prefix}.class:: #{klass}\n" if klass
140
+ out += "#{prefix}.partnumber:: #{partnumber}\n" if partnumber
141
+ out += "#{prefix}.edition:: #{edition}\n" if edition
142
+ out += "#{prefix}.version:: #{version}\n" if version
143
+ out += "#{prefix}.supplementtype:: #{supplementtype}\n" if supplementtype
144
+ if supplementnumber
145
+ out += "#{prefix}.supplementnumber:: #{supplementnumber}\n"
146
+ end
147
+ out += "#{prefix}.language:: #{language}\n" if language
148
+ out += "#{prefix}.year:: #{year}\n" if year
149
+ out
150
+ end
151
+
122
152
  def remove_date
123
153
  if @type == "Chinese Standard"
124
154
  @docnumber.sub!(/-[12]\d\d\d/, "")
@@ -21,5 +21,16 @@ module RelatonBib
21
21
  def to_hash
22
22
  workgroup.to_hash
23
23
  end
24
+
25
+ # @param prefix [String]
26
+ # @param count [Integer] number of technical committees
27
+ # @return [String]
28
+ def to_asciibib(prefix = "", count = 1)
29
+ pref = prefix.empty? ? prefix : prefix + "."
30
+ pref += "technical_committee"
31
+ out = count > 1 ? "#{pref}::\n" : ""
32
+ out += workgroup.to_asciibib pref
33
+ out
34
+ end
24
35
  end
25
36
  end
@@ -6,14 +6,12 @@ module RelatonBib
6
6
  # @return [RelatonBib::FormattedString]
7
7
  attr_reader :title
8
8
 
9
- # rubocop:disable Metrics/MethodLength
10
-
11
9
  # @param type [String]
12
10
  # @param title [RelatonBib::FormattedString, Hash]
13
11
  # @param content [String]
14
12
  # @param language [String]
15
13
  # @param script [String]
16
- def initialize(**args)
14
+ def initialize(**args) # rubocop:disable Metrics/MethodLength
17
15
  unless args[:title] || args[:content]
18
16
  raise ArgumentError, %{Keyword "title" or "content" should be passed.}
19
17
  end
@@ -29,7 +27,6 @@ module RelatonBib
29
27
  @title = FormattedString.new(fsargs)
30
28
  end
31
29
  end
32
- # rubocop:enable Metrics/MethodLength
33
30
 
34
31
  # @param title [String]
35
32
  # @return [Array<self>]
@@ -50,15 +47,13 @@ module RelatonBib
50
47
  case ttls.size
51
48
  when 0, 1 then [nil, ttls.first.to_s, nil]
52
49
  else intro_or_part ttls
53
- # when 2, 3 then intro_or_part ttls
54
- # else [ttls[0], ttls[1], ttls[2..-1].join(" -- ")]
55
50
  end
56
51
  end
57
52
 
58
53
  # @param ttls [Array<String>]
59
54
  # @return [Array<Strin, nil>]
60
55
  def self.intro_or_part(ttls)
61
- if /^(Part|Partie) \d+:/ =~ ttls[1]
56
+ if /^(Part|Partie) \d+:/.match? ttls[1]
62
57
  [nil, ttls[0], ttls[1..-1].join(" -- ")]
63
58
  else
64
59
  parts = ttls.slice(2..-1)
@@ -86,5 +81,16 @@ module RelatonBib
86
81
  end
87
82
  hash
88
83
  end
84
+
85
+ # @param prefix [String]
86
+ # @param count [Integer] number of titles
87
+ # @return [String]
88
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
89
+ pref = prefix.empty? ? prefix : prefix + "."
90
+ out = count > 1 ? "#{pref}title::\n" : ""
91
+ out += "#{pref}title.type:: #{type}\n" if type
92
+ out += title.to_asciibib "#{pref}title"
93
+ out
94
+ end
89
95
  end
90
96
  end