relaton-bib 1.20.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +1 -1
  4. data/CLAUDE.md +96 -0
  5. data/Gemfile +1 -4
  6. data/README.adoc +195 -154
  7. data/bin/console +1 -1
  8. data/grammars/basicdoc.rng +1572 -671
  9. data/grammars/biblio-standoc.rng +107 -46
  10. data/grammars/biblio.rng +1012 -377
  11. data/grammars/versions.json +26 -26
  12. data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
  13. data/lib/relaton/bib/converter/asciibib.rb +13 -0
  14. data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
  15. data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
  16. data/lib/relaton/bib/converter/bibtex.rb +23 -0
  17. data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +383 -0
  18. data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
  19. data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +305 -0
  20. data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
  21. data/lib/relaton/bib/converter/bibxml.rb +51 -0
  22. data/lib/relaton/bib/hash_parser_v1.rb +754 -0
  23. data/lib/relaton/bib/item_data.rb +229 -0
  24. data/lib/relaton/bib/model/abstract.rb +16 -0
  25. data/lib/relaton/bib/model/address.rb +22 -0
  26. data/lib/relaton/bib/model/affiliation.rb +16 -0
  27. data/lib/relaton/bib/model/bibdata.rb +24 -0
  28. data/lib/relaton/bib/model/bibitem.rb +23 -0
  29. data/lib/relaton/bib/model/contact.rb +18 -0
  30. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  31. data/lib/relaton/bib/model/contributor.rb +71 -0
  32. data/lib/relaton/bib/model/copyright.rb +27 -0
  33. data/lib/relaton/bib/model/date.rb +31 -0
  34. data/lib/relaton/bib/model/depiction.rb +16 -0
  35. data/lib/relaton/bib/model/docidentifier.rb +33 -0
  36. data/lib/relaton/bib/model/doctype.rb +14 -0
  37. data/lib/relaton/bib/model/edition.rb +14 -0
  38. data/lib/relaton/bib/model/ext.rb +26 -0
  39. data/lib/relaton/bib/model/extent.rb +16 -0
  40. data/lib/relaton/bib/model/formattedref.rb +43 -0
  41. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  42. data/lib/relaton/bib/model/fullname.rb +11 -0
  43. data/lib/relaton/bib/model/ics.rb +23 -0
  44. data/lib/relaton/bib/model/image.rb +28 -0
  45. data/lib/relaton/bib/model/item.rb +137 -0
  46. data/lib/relaton/bib/model/item_base.rb +27 -0
  47. data/lib/relaton/bib/model/keyword.rb +30 -0
  48. data/lib/relaton/bib/model/locality.rb +18 -0
  49. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  50. data/lib/relaton/bib/model/localized_string.rb +57 -0
  51. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  52. data/lib/relaton/bib/model/logo.rb +14 -0
  53. data/lib/relaton/bib/model/medium.rb +22 -0
  54. data/lib/relaton/bib/model/note.rb +16 -0
  55. data/lib/relaton/bib/model/organization.rb +13 -0
  56. data/lib/relaton/bib/model/organization_type.rb +42 -0
  57. data/lib/relaton/bib/model/person.rb +36 -0
  58. data/lib/relaton/bib/model/phone.rb +14 -0
  59. data/lib/relaton/bib/model/place.rb +33 -0
  60. data/lib/relaton/bib/model/price.rb +14 -0
  61. data/lib/relaton/bib/model/relation.rb +43 -0
  62. data/lib/relaton/bib/model/series.rb +34 -0
  63. data/lib/relaton/bib/model/size.rb +23 -0
  64. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  65. data/lib/relaton/bib/model/status.rb +27 -0
  66. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  67. data/lib/relaton/bib/model/subdivision.rb +16 -0
  68. data/lib/relaton/bib/model/title.rb +56 -0
  69. data/lib/relaton/bib/model/type/string_date.rb +48 -0
  70. data/lib/relaton/bib/model/uri.rb +18 -0
  71. data/lib/relaton/bib/model/validity.rb +16 -0
  72. data/lib/relaton/bib/model/version.rb +14 -0
  73. data/lib/relaton/bib/namespace_helper.rb +21 -0
  74. data/lib/relaton/bib/util.rb +18 -0
  75. data/lib/relaton/bib/version.rb +5 -0
  76. data/lib/relaton/bib.rb +45 -0
  77. data/relaton-bib.gemspec +11 -8
  78. metadata +125 -67
  79. data/lib/relaton_bib/bib_item_locality.rb +0 -175
  80. data/lib/relaton_bib/biblio_note.rb +0 -72
  81. data/lib/relaton_bib/biblio_version.rb +0 -46
  82. data/lib/relaton_bib/bibliographic_date.rb +0 -119
  83. data/lib/relaton_bib/bibliographic_item.rb +0 -668
  84. data/lib/relaton_bib/bibliographic_size.rb +0 -103
  85. data/lib/relaton_bib/bibtex_parser.rb +0 -246
  86. data/lib/relaton_bib/bibxml_parser.rb +0 -422
  87. data/lib/relaton_bib/classification.rb +0 -40
  88. data/lib/relaton_bib/config.rb +0 -16
  89. data/lib/relaton_bib/contribution_info.rb +0 -117
  90. data/lib/relaton_bib/contributor.rb +0 -277
  91. data/lib/relaton_bib/copyright_association.rb +0 -79
  92. data/lib/relaton_bib/deep_dup.rb +0 -30
  93. data/lib/relaton_bib/document_identifier.rb +0 -118
  94. data/lib/relaton_bib/document_relation.rb +0 -95
  95. data/lib/relaton_bib/document_relation_collection.rb +0 -57
  96. data/lib/relaton_bib/document_status.rb +0 -92
  97. data/lib/relaton_bib/document_type.rb +0 -52
  98. data/lib/relaton_bib/edition.rb +0 -55
  99. data/lib/relaton_bib/editorial_group.rb +0 -41
  100. data/lib/relaton_bib/extent.rb +0 -39
  101. data/lib/relaton_bib/forename.rb +0 -65
  102. data/lib/relaton_bib/formatted_ref.rb +0 -17
  103. data/lib/relaton_bib/formatted_string.rb +0 -133
  104. data/lib/relaton_bib/full_name.rb +0 -108
  105. data/lib/relaton_bib/hash_converter.rb +0 -568
  106. data/lib/relaton_bib/hit.rb +0 -52
  107. data/lib/relaton_bib/hit_collection.rb +0 -105
  108. data/lib/relaton_bib/ics.rb +0 -42
  109. data/lib/relaton_bib/image.rb +0 -95
  110. data/lib/relaton_bib/localized_string.rb +0 -149
  111. data/lib/relaton_bib/medium.rb +0 -76
  112. data/lib/relaton_bib/organization.rb +0 -165
  113. data/lib/relaton_bib/person.rb +0 -129
  114. data/lib/relaton_bib/place.rb +0 -203
  115. data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
  116. data/lib/relaton_bib/renderer/bibxml.rb +0 -296
  117. data/lib/relaton_bib/series.rb +0 -119
  118. data/lib/relaton_bib/structured_identifier.rb +0 -173
  119. data/lib/relaton_bib/technical_committee.rb +0 -34
  120. data/lib/relaton_bib/typed_title_string.rb +0 -191
  121. data/lib/relaton_bib/typed_uri.rb +0 -57
  122. data/lib/relaton_bib/util.rb +0 -16
  123. data/lib/relaton_bib/validity.rb +0 -52
  124. data/lib/relaton_bib/version.rb +0 -3
  125. data/lib/relaton_bib/workers_pool.rb +0 -43
  126. data/lib/relaton_bib/workgroup.rb +0 -58
  127. data/lib/relaton_bib/xml_parser.rb +0 -718
  128. data/lib/relaton_bib.rb +0 -111
@@ -1,277 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "uri"
4
-
5
- module RelatonBib
6
- # Address class.
7
- class Address
8
- # @return [Array<String>]
9
- attr_reader :street
10
-
11
- # @return [String, nil]
12
- attr_reader :city, :state, :country, :postcode, :formatted_address
13
-
14
- # @param street [Array<String>] streets
15
- # @param city [String, nil] city, should be present or formatted address provided
16
- # @param state [String, nil] state
17
- # @param country [String, nil] country, should be present or formatted address provided
18
- # @param postcode [String, nil] postcode
19
- # @param formatted_address [String, nil] formatted address, should be present or city and country provided
20
- def initialize(**args) # rubocop:disable Metrics/CyclomaticComplexity
21
- unless args[:formatted_address] || (args[:city] && args[:country])
22
- raise ArgumentError, "Either formatted address or city and country must be provided"
23
- end
24
-
25
- @street = args[:street] || []
26
- @city = args[:city]
27
- @state = args[:state]
28
- @country = args[:country]
29
- @postcode = args[:postcode]
30
- @formatted_address = args[:formatted_address] unless args[:city] && args[:country]
31
- end
32
-
33
- def ==(other)
34
- street == other.street && city == other.city && state == other.state &&
35
- country == other.country && postcode == other.postcode &&
36
- formatted_address == other.formatted_address
37
- end
38
-
39
- # @param doc [Nokogiri::XML::Document]
40
- def to_xml(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
- doc.address do
42
- if formatted_address
43
- doc.formattedAddress formatted_address
44
- else
45
- street.each { |str| doc.street str }
46
- doc.city city
47
- doc.state state if state
48
- doc.country country
49
- doc.postcode postcode if postcode
50
- end
51
- end
52
- end
53
-
54
- # @return [Hash]
55
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
56
- hash = { "address" => {} }
57
- if formatted_address
58
- hash["address"]["formatted_address"] = formatted_address
59
- else
60
- hash["address"]["street"] = street if street.any?
61
- hash["address"]["city"] = city
62
- hash["address"]["state"] = state if state
63
- hash["address"]["country"] = country
64
- hash["address"]["postcode"] = postcode if postcode
65
- end
66
- hash
67
- end
68
-
69
- # @param prefix [String]
70
- # @param count [Integer] number of addresses
71
- # @return [String]
72
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
73
- pref = prefix.empty? ? "address" : "#{prefix}.address"
74
- if formatted_address
75
- "#{pref}.formatted_address:: #{formatted_address}\n"
76
- else
77
- out = count > 1 ? "#{pref}::\n" : ""
78
- street.each { |st| out += "#{pref}.street:: #{st}\n" }
79
- out += "#{pref}.city:: #{city}\n"
80
- out += "#{pref}.state:: #{state}\n" if state
81
- out += "#{pref}.country:: #{country}\n"
82
- out += "#{pref}.postcode:: #{postcode}\n" if postcode
83
- out
84
- end
85
- end
86
- end
87
-
88
- # Contact class.
89
- class Contact
90
- # @return [String] allowed "phone", "email" or "uri"
91
- attr_reader :type
92
-
93
- # @return [String, nil]
94
- attr_reader :subtype
95
-
96
- # @return [String]
97
- attr_reader :value
98
-
99
- # @param type [String] allowed "phone", "email" or "uri"
100
- # @param subtype [String, nil] i.e. "fax", "mobile", "landline" for "phone"
101
- # or "work", "personal" for "uri" type
102
- # @param value [String]
103
- def initialize(type:, value:, subtype: nil)
104
- @type = type
105
- @subtype = subtype
106
- @value = value
107
- end
108
-
109
- def ==(other)
110
- type == other.type && subtype == other.subtype && value == other.value
111
- end
112
-
113
- # @param builder [Nokogiri::XML::Document]
114
- def to_xml(builder)
115
- node = builder.send type, value
116
- node["type"] = subtype if subtype
117
- end
118
-
119
- # @return [Hash]
120
- def to_hash
121
- hash = { type => value }
122
- hash["type"] = subtype if subtype
123
- hash
124
- end
125
-
126
- # @param prefix [String]
127
- # @param count [Integer] number of contacts
128
- # @return [string]
129
- def to_asciibib(prefix = "", count = 1)
130
- pref = prefix.empty? ? prefix : "#{prefix}."
131
- out = count > 1 ? "#{pref}contact::\n" : ""
132
- out += "#{pref}contact.#{type}:: #{value}\n"
133
- out += "#{pref}contact.type:: #{subtype}\n" if subtype
134
- out
135
- end
136
- end
137
-
138
- # Affiliation.
139
- class Affiliation
140
- include RelatonBib
141
-
142
- # @return [RelatonBib::LocalizedString, nil]
143
- attr_reader :name
144
-
145
- # @return [RelatonBib::Organization]
146
- attr_reader :organization
147
-
148
- # @param organization [RelatonBib::Organization, nil]
149
- # @param name [RelatonBib::LocalizedString, nil]
150
- # @param description [Array<RelatonBib::FormattedString>]
151
- def initialize(organization: nil, name: nil, description: [])
152
- @name = name
153
- @organization = organization
154
- @description = description
155
- end
156
-
157
- def ==(other)
158
- name == other.name && organization == other.organization && description == other.description
159
- end
160
-
161
- # @param opts [Hash]
162
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
163
- # @option opts [String] :lang language
164
- def to_xml(**opts)
165
- return unless organization || name || description&.any?
166
-
167
- opts[:builder].affiliation do |builder|
168
- name_xml builder
169
- description_xml builder
170
- organization&.to_xml(**opts)
171
- end
172
- end
173
-
174
- def name_xml(builder)
175
- builder.name { name.to_xml builder } if name
176
- end
177
-
178
- def description_xml(builder)
179
- description.each { |d| builder.description { d.to_xml builder } }
180
- end
181
-
182
- #
183
- # Get description.
184
- #
185
- # @param [String, nil] lang language if nil return all description
186
- #
187
- # @return return [Array<RelatonBib::FormattedString>] description
188
- #
189
- def description(lang = nil)
190
- return @description unless lang
191
-
192
- @description.select { |d| d.language&.include? lang }
193
- end
194
-
195
- #
196
- # Render affiliation as hash.
197
- #
198
- # @return [Hash]
199
- #
200
- def to_hash
201
- hash = organization&.to_hash || {}
202
- hash["name"] = name.to_hash if name
203
- if description&.any?
204
- hash["description"] = single_element_array(description)
205
- end
206
- hash
207
- end
208
-
209
- # @param prefix [String]
210
- # @param count [Integer]
211
- # @return [String]
212
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
213
- pref = prefix.empty? ? prefix : "#{prefix}."
214
- out = count > 1 ? "#{pref}affiliation::\n" : ""
215
- out += name.to_asciibib "#{pref}affiliation.name" if name
216
- description.each do |d|
217
- out += d.to_asciibib "#{pref}affiliation.description", description.size
218
- end
219
- out += organization.to_asciibib "#{pref}affiliation.*" if organization
220
- out
221
- end
222
- end
223
-
224
- # Contributor.
225
- class Contributor
226
- include RelatonBib
227
-
228
- # @return [URI]
229
- attr_reader :uri
230
-
231
- # @return [Array<RelatonBib::Address, RelatonBib::Contact>]
232
- attr_reader :contact
233
-
234
- # @param url [String, nil]
235
- # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
236
- def initialize(url: nil, contact: [])
237
- @uri = URI url if url
238
- @contact = contact
239
- end
240
-
241
- def ==(other)
242
- uri == other.uri && contact == other.contact
243
- end
244
-
245
- # Returns url.
246
- # @return [String]
247
- def url
248
- @uri.to_s
249
- end
250
-
251
- # @params builder [Nokogiri::XML::Builder]
252
- def to_xml(builder)
253
- contact.each { |contact| contact.to_xml builder }
254
- end
255
-
256
- # @return [Hash]
257
- def to_hash
258
- hash = {}
259
- hash["url"] = uri.to_s if uri
260
- hash["contact"] = single_element_array(contact) if contact&.any?
261
- hash
262
- end
263
-
264
- # @param prefix [String]
265
- # @return [String]
266
- def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
267
- pref = prefix.empty? ? prefix : "#{prefix}."
268
- out = ""
269
- out += "#{pref}url:: #{uri}\n" if uri
270
- addr = contact.select { |c| c.is_a? RelatonBib::Address }
271
- addr.each { |ct| out += ct.to_asciibib prefix, addr.size }
272
- cont = contact.select { |c| c.is_a? RelatonBib::Contact }
273
- cont.each { |ct| out += ct.to_asciibib prefix, cont.size }
274
- out
275
- end
276
- end
277
- end
@@ -1,79 +0,0 @@
1
- module RelatonBib
2
- # Copyright association.
3
- class CopyrightAssociation
4
- include RelatonBib
5
-
6
- # @return [Date]
7
- attr_reader :from
8
-
9
- # @return [Date, nil]
10
- attr_reader :to
11
-
12
- # @return [String, nil]
13
- attr_reader :scope
14
-
15
- # @return [Array<RelatonBib::ContributionInfo>]
16
- attr_reader :owner
17
-
18
- # rubocop:disable Metrics/AbcSize
19
-
20
- # @param owner [Array<Hash, RelatonBib::ContributionInfo>] contributor
21
- # @option owner [String] :name
22
- # @option owner [String] :abbreviation
23
- # @option owner [String] :url
24
- # @param from [String] date
25
- # @param to [String, nil] date
26
- # @param scope [String, nil]
27
- def initialize(owner:, from:, to: nil, scope: nil)
28
- unless owner.any?
29
- raise ArgumentError, "at least one owner should exist."
30
- end
31
-
32
- @owner = owner.map do |o|
33
- o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(**o)) : o
34
- end
35
-
36
- @from = Date.strptime(from.to_s, "%Y") if from.to_s.match?(/\d{4}/)
37
- @to = Date.strptime(to.to_s, "%Y") unless to.to_s.empty?
38
- @scope = scope
39
- end
40
-
41
- # @param opts [Hash]
42
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
43
- # @option opts [String, Symbol] :lang language
44
- def to_xml(**opts)
45
- opts[:builder].copyright do |builder|
46
- builder.from from ? from.year : "unknown"
47
- builder.to to.year if to
48
- owner.each { |o| builder.owner { o.to_xml(**opts) } }
49
- builder.scope scope if scope
50
- end
51
- end
52
- # rubocop:enable Metrics/AbcSize
53
-
54
- # @return [Hash]
55
- def to_hash # rubocop:disable Metrics/AbcSize
56
- owners = single_element_array(owner.map { |o| o.to_hash["organization"] })
57
- hash = {
58
- "owner" => owners,
59
- "from" => from.year.to_s,
60
- }
61
- hash["to"] = to.year.to_s if to
62
- hash["scope"] = scope if scope
63
- hash
64
- end
65
-
66
- # @param prefix [String]
67
- # @param count [Iteger] number of copyright elements
68
- # @return [String]
69
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
70
- pref = prefix.empty? ? "copyright" : "#{prefix}.copyright"
71
- out = count > 1 ? "#{pref}::\n" : ""
72
- owner.each { |ow| out += ow.to_asciibib "#{pref}.owner", owner.size }
73
- out += "#{pref}.from:: #{from.year}\n" if from
74
- out += "#{pref}.to:: #{to.year}\n" if to
75
- out += "#{pref}.scope:: #{scope}\n" if scope
76
- out
77
- end
78
- end
79
- end
@@ -1,30 +0,0 @@
1
- class Object
2
- def duplicable?
3
- true
4
- end
5
-
6
- def deep_dup
7
- duplicable? ? dup : self
8
- end
9
- end
10
-
11
- class Array
12
- def deep_dup
13
- map(&:deep_dup)
14
- end
15
- end
16
-
17
- # class Hash
18
- # def deep_dup
19
- # hash = dup
20
- # each_pair do |key, value|
21
- # if key.frozen? && ::String === key
22
- # hash[key] = value.deep_dup
23
- # else
24
- # hash.delete(key)
25
- # hash[key.deep_dup] = value.deep_dup
26
- # end
27
- # end
28
- # hash
29
- # end
30
- # end
@@ -1,118 +0,0 @@
1
- module RelatonBib
2
- # Document identifier.
3
- class DocumentIdentifier
4
- # @return [String]
5
- attr_reader :id
6
-
7
- # @return [String, nil]
8
- attr_reader :type, :scope, :language, :script
9
-
10
- # @param type [Boolean, nil]
11
- attr_reader :primary
12
-
13
- # @param id [String]
14
- # @param type [String, nil]
15
- # @param scope [String, nil]
16
- # @param primary [Bolean, nil]
17
- # @param language [String, nil]
18
- def initialize(**args)
19
- @id = args[:id]
20
- @type = args[:type]
21
- @scope = args[:scope]
22
- @primary = args[:primary]
23
- @language = args[:language]
24
- @script = args[:script]
25
- end
26
-
27
- # in docid manipulations, assume ISO as the default: id-part:year
28
- def remove_part
29
- case @type
30
- when "Chinese Standard" then @id.sub!(/\.\d+/, "")
31
- when "URN" then remove_urn_part
32
- else @id.sub!(/-[^:]+/, "")
33
- end
34
- end
35
-
36
- def remove_date
37
- case @type
38
- when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "")
39
- when "URN"
40
- @id.sub!(/^(urn:iec:std:[^:]+:[^:]+:)[^:]*/, '\1')
41
- else @id.sub!(/:[12]\d\d\d/, "")
42
- end
43
- end
44
-
45
- def all_parts
46
- if type == "URN"
47
- @id.sub!(%r{^(urn:iec:std(?::[^:]*){4}).*}, '\1:ser')
48
- else
49
- @id += " (all parts)"
50
- end
51
- end
52
-
53
- #
54
- # Add docidentifier xml element
55
- #
56
- # @param opts [Hash]
57
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
58
- # @option opts [String] :lang language
59
- def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
60
- lid = if type == "URN" && opts[:lang]
61
- id.sub %r{(?<=:)(?:\w{2},)*?(#{opts[:lang]})(?:,\w{2})*}, '\1'
62
- else id
63
- end
64
- element = opts[:builder].docidentifier { |b| b.parent.inner_html = lid }
65
- element[:type] = type if type
66
- element[:scope] = scope if scope
67
- element[:primary] = primary if primary
68
- element[:language] = language if language
69
- element[:script] = script if script
70
- end
71
-
72
- # @return [Hash]
73
- def to_hash # rubocop:disable Metrics/AbcSize
74
- hash = { "id" => id }
75
- hash["type"] = type if type
76
- hash["scope"] = scope if scope
77
- hash["primary"] = primary if primary
78
- hash["language"] = language if language
79
- hash["script"] = script if script
80
- hash
81
- end
82
-
83
- # @param prefix [String]
84
- # @param count [Integer] number of docids
85
- # @return [String]
86
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
87
- pref = prefix.empty? ? prefix : "#{prefix}."
88
- return "#{pref}docid:: #{id}\n" unless type || scope
89
-
90
- out = count > 1 ? "#{pref}docid::\n" : ""
91
- out += "#{pref}docid.type:: #{type}\n" if type
92
- out += "#{pref}docid.scope:: #{scope}\n" if scope
93
- out += "#{pref}docid.primary:: #{primary}\n" if primary
94
- out += "#{pref}docid.language:: #{language}\n" if language
95
- out += "#{pref}docid.script:: #{script}\n" if script
96
- out + "#{pref}docid.id:: #{id}\n"
97
- end
98
-
99
- private
100
-
101
- def remove_urn_part # rubocop:disable Metrics/MethodLength
102
- @id.sub!(%r{^
103
- (urn:iso:std:[^:]+ # ISO prefix and originator
104
- (?::(?:data|guide|isp|iwa|pas|r|tr|ts|tta)) # type
105
- ?:\d+) # docnumber
106
- (?::-[^:]+)? # partnumber
107
- (?::(draft|cancelled|stage-[^:]+))? # status
108
- (?::ed-\d+)?(?::v[^:]+)? # edition and version
109
- (?::\w{2}(?:,\w{2})*)? # langauge
110
- }x, '\1') # remove partnumber, status, version, and language
111
- @id.sub!(%r{^
112
- (urn:iec:std:[^:]+ # IEC prefix and originator
113
- :\d+) # docnumber
114
- (?:-[^:]+)? # partnumber
115
- }x, '\1') # remove partnumber
116
- end
117
- end
118
- end
@@ -1,95 +0,0 @@
1
- module RelatonBib
2
- # Documett relation
3
- class DocumentRelation
4
- include RelatonBib
5
-
6
- TYPES = %w[
7
- includes includedIn hasPart partOf merges mergedInto splits splitInto
8
- instanceOf hasInstance exemplarOf hasExemplar manifestationOf
9
- hasManifestation reproductionOf hasReproduction reprintOf hasReprint
10
- expressionOf hasExpression translatedFrom hasTranslation arrangementOf
11
- hasArrangement abridgementOf hasAbridgement annotationOf hasAnnotation
12
- draftOf hasDraft editionOf hasEdition updates updatedBy derivedFrom
13
- derives describes describedBy catalogues cataloguedBy hasSuccessor
14
- successorOf adaptedFrom hasAdaptation adoptedFrom adoptedAs reviewOf
15
- hasReview commentaryOf hasCommentary related hasComplement complementOf
16
- obsoletes obsoletedBy cites isCitedIn
17
- ].freeze
18
-
19
- # @return [String]
20
- attr_accessor :type
21
-
22
- # @return [RelatonBib::FormattedString, nil]
23
- attr_reader :description
24
-
25
- # @return [String]
26
- # attr_reader :identifier, :url
27
-
28
- # @return [RelatonBib::BibliographicItem]
29
- attr_reader :bibitem
30
-
31
- # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
32
- attr_reader :locality
33
-
34
- # @return [Array<RelatonBib::SourceLocality,
35
- # RelatonBib::SourceLocalityStack>]
36
- attr_reader :source_locality
37
-
38
- # @param type [String]
39
- # @param description [RelatonBib::FormattedString, nil]
40
- # @param bibitem [RelatonBib::BibliographicItem,
41
- # RelatonIso::IsoBibliographicItem]
42
- # @param locality [Array<RelatonBib::Locality>]
43
- # @param locality_stack [Array<RelatonBib::LocalityStack>]
44
- # @param source_locality [Array<RelatonBib::SourceLocality,
45
- # RelatonBib::SourceLocalityStack>]
46
- def initialize(type:, bibitem:, **args)
47
- type = "obsoletes" if type == "Now withdrawn"
48
- unless self.class::TYPES.include? type
49
- Util.warn "Invalid relation type: `#{type}`"
50
- end
51
- @type = type
52
- @description = args[:description]
53
- @locality = args[:locality] || args[:locality_stack] || []
54
- @source_locality = args[:source_locality] || args[:source_locality_stack] || []
55
- @bibitem = bibitem
56
- end
57
-
58
- # @param builder [Nokogiri::XML::Builder]
59
- def to_xml(builder, **opts)
60
- opts.delete :bibdata
61
- opts.delete :note
62
- builder.relation(type: type) do
63
- builder.description { description.to_xml builder } if description
64
- bibitem.to_xml(**opts.merge(builder: builder, embedded: true))
65
- locality.each { |l| l.to_xml builder }
66
- source_locality.each { |l| l.to_xml builder }
67
- end
68
- end
69
-
70
- # @return [Hash]
71
- def to_hash # rubocop:disable Metrics/AbcSize
72
- hash = { "type" => type, "bibitem" => bibitem.to_hash(embedded: true) }
73
- hash["description"] = description.to_hash if description
74
- locality.each_with_object(hash) do |l, obj|
75
- k, v = l.to_hash.first
76
- hash[k] ||= []
77
- hash[k] << v
78
- end
79
- if source_locality&.any?
80
- hash["source_locality"] = single_element_array(source_locality)
81
- end
82
- hash
83
- end
84
-
85
- # @param prefix [String]
86
- # @return [String]
87
- def to_asciibib(prefix = "")
88
- pref = prefix.empty? ? prefix : prefix + "."
89
- out = "#{prefix}.type:: #{type}\n"
90
- out += description.to_asciibib "#{pref}desctiption" if description
91
- out += bibitem.to_asciibib "#{pref}bibitem" if bibitem
92
- out
93
- end
94
- end
95
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RelatonBib
4
- # Document relation collection
5
- class DocRelationCollection
6
- extend Forwardable
7
-
8
- def_delegators :@array, :<<, :[], :first, :last, :empty?, :any?, :size,
9
- :each, :detect, :map, :reduce, :length, :unshift, :max_by
10
-
11
- # @param relation [Array<RelatonBib::DocumentRelation, Hash>]
12
- # @option relation [String] :type
13
- # @option relation [String] :identifier
14
- # @option relation [String, NIllClass] :url (nil)
15
- # @option relation [Array<RelatonBib::Locality, RelatonBib::LocalityStack>] :locality
16
- # @option relation [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>] :source_locality
17
- # @option relation [RelatonBib::BibliographicItem, nil] :bibitem (nil)
18
- def initialize(relation)
19
- @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(**r) : r }
20
- end
21
-
22
- #
23
- # Returns new DocumentRelationCollection with selected relations.
24
- #
25
- # @example Select relations with type "obsoletes"
26
- # relations.select { |r| r.type == "obsoletes" }
27
- # #=> <RelatonBib::DocRelationCollection:0x00007f9a0191d5f0 @array=[...]>
28
- #
29
- # @return [RelatonBib::DocRelationCollection] new DocumentRelationCollection
30
- # with selected relations
31
- #
32
- def select(&block)
33
- arr = @array.select(&block)
34
- self.class.new arr
35
- end
36
-
37
- # @todo We don't have replace type anymore. Suppose we should update this
38
- # method or delete it.
39
- #
40
- # @return [RelatonBib::DocRelationCollection]
41
- def replaces
42
- DocRelationCollection.new(@array.select { |r| r.type == "replace" })
43
- end
44
-
45
- # @param prefix [String]
46
- # @return [String]
47
- def to_asciibib(prefix = "")
48
- pref = prefix.empty? ? "relation" : "#{prefix}.relation"
49
- out = ""
50
- @array.each do |r|
51
- out += size > 1 ? "#{pref}::\n" : ""
52
- out += r.to_asciibib pref
53
- end
54
- out
55
- end
56
- end
57
- end