relaton-iso-bib 1.1.1 → 1.5.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.
@@ -253,7 +253,7 @@
253
253
  <define name="preface">
254
254
  <element name="preface">
255
255
  <optional>
256
- <ref name="preface_abstract"/>
256
+ <ref name="abstract"/>
257
257
  </optional>
258
258
  <ref name="foreword"/>
259
259
  <optional>
@@ -362,6 +362,9 @@
362
362
  <data type="boolean"/>
363
363
  </attribute>
364
364
  </optional>
365
+ <optional>
366
+ <attribute name="number"/>
367
+ </optional>
365
368
  <optional>
366
369
  <attribute name="subsequence"/>
367
370
  </optional>
@@ -402,6 +405,13 @@
402
405
  -->
403
406
  <define name="iso-standard">
404
407
  <element name="iso-standard">
408
+ <attribute name="version"/>
409
+ <attribute name="type">
410
+ <choice>
411
+ <value>semantic</value>
412
+ <value>presentation</value>
413
+ </choice>
414
+ </attribute>
405
415
  <ref name="bibdata"/>
406
416
  <zeroOrMore>
407
417
  <ref name="termdocsource"/>
@@ -33,7 +33,7 @@ module RelatonIsoBib
33
33
  # @option workgroup [Integer] :number
34
34
  #
35
35
  # @param secretariat [String, NilClass]
36
- def initialize(technical_committee:, **args)
36
+ def initialize(technical_committee:, **args) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
37
37
  @technical_committee = technical_committee.map do |tc|
38
38
  tc.is_a?(Hash) ? IsoSubgroup.new(tc) : tc
39
39
  end
@@ -46,11 +46,15 @@ module RelatonIsoBib
46
46
  @secretariat = args[:secretariat]
47
47
  end
48
48
 
49
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
49
+ # @return [true]
50
+ def presence?
51
+ true
52
+ end
50
53
 
51
54
  # @param builder [Nokogiri::XML::Builder]
52
- def to_xml(builder)
53
- return unless technical_committee || subcommittee || workgroup || secretariat
55
+ def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize, Metrics/MethodLength
56
+ return unless technical_committee || subcommittee || workgroup ||
57
+ secretariat
54
58
 
55
59
  builder.editorialgroup do
56
60
  technical_committee.each do |tc|
@@ -65,16 +69,39 @@ module RelatonIsoBib
65
69
  builder.secretariat secretariat if secretariat
66
70
  end
67
71
  end
68
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
69
72
 
70
73
  # @return [Hash]
71
- def to_hash
72
- hash = { "technical_committee" => single_element_array(technical_committee) }
73
- hash["subcommittee"] = single_element_array(subcommittee) if subcommittee&.any?
74
+ def to_hash # rubocop:disable Metrics/AbcSize
75
+ hash = {
76
+ "technical_committee" => single_element_array(technical_committee),
77
+ }
78
+ if subcommittee&.any?
79
+ hash["subcommittee"] = single_element_array(subcommittee)
80
+ end
74
81
  hash["workgroup"] = single_element_array(workgroup) if workgroup&.any?
75
82
  hash["secretariat"] = secretariat if secretariat
76
83
  hash
77
84
  end
85
+
86
+ # @param prefix [String]
87
+ # @return [String]
88
+ def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
89
+ pref = prefix.empty? ? prefix : prefix + "."
90
+ pref += "editorialgroup"
91
+ out = ""
92
+ technical_committee.each do |tc|
93
+ out += tc.to_asciibib "#{pref}.technical_committee",
94
+ technical_committee.size
95
+ end
96
+ subcommittee.each do |sc|
97
+ out += sc.to_asciibib "#{pref}.subcommittee", subcommittee.size
98
+ end
99
+ workgroup.each do |wg|
100
+ out += wg.to_asciibib "#{pref}.workgroup", workgroup.size
101
+ end
102
+ out += "#{pref}.secretariat:: #{secretariat}\n" if secretariat
103
+ out
104
+ end
78
105
  end
79
106
 
80
107
  # ISO subgroup.
@@ -111,5 +138,15 @@ module RelatonIsoBib
111
138
  hash["number"] = number if number
112
139
  hash
113
140
  end
141
+
142
+ # @param prefix [String]
143
+ # @param count [Integer] number of the elements
144
+ def to_asciibib(prefix, count = 1)
145
+ out = count > 1 ? "#{prefix}::\n" : ""
146
+ out += "#{prefix}.type:: #{type}\n" if type
147
+ out += "#{prefix}.number:: #{number}\n" if number
148
+ out += "#{prefix}.name:: #{name}\n"
149
+ out
150
+ end
114
151
  end
115
152
  end
@@ -1,75 +1,8 @@
1
1
  module RelatonIsoBib
2
2
  class HashConverter < RelatonBib::HashConverter
3
3
  class << self
4
- # @override RelatonBib::HashConverter.hash_to_bib
5
- # @param args [Hash]
6
- # @param nested [TrueClass, FalseClass]
7
- # @return [Hash]
8
- def hash_to_bib(args, nested = false)
9
- ret = super
10
- return if ret.nil?
11
-
12
- editorialgroup_hash_to_bib(ret)
13
- ics_hash_to_bib(ret)
14
- structuredidentifier_hash_to_bib(ret)
15
- ret
16
- end
17
-
18
- def split_title(content, lang = "en", script = "Latn")
19
- titles = content&.split(/ (?:--|—|–) /)
20
- case titles&.size
21
- when nil, 0
22
- intro, main, part = nil, "", nil
23
- when 1
24
- intro, main, part = nil, titles[0], nil
25
- when 2
26
- if /^(Part|Partie) \d+:/ =~ titles[1]
27
- intro, main, part = nil, titles[0], titles[1]
28
- else
29
- intro, main, part = titles[0], titles[1], nil
30
- end
31
- when 3
32
- intro, main, part = titles[0], titles[1], titles[2]
33
- else
34
- intro, main, part = titles[0], titles[1], titles[2..-1]&.join(" -- ")
35
- end
36
- {
37
- title_intro: intro,
38
- title_main: main,
39
- title_part: part,
40
- language: lang,
41
- script: script,
42
- }
43
- end
44
-
45
4
  private
46
5
 
47
- #
48
- # Ovverides superclass's method
49
- #
50
- # @param ret [Hash]
51
- def title_hash_to_bib(ret)
52
- return unless ret[:title]
53
-
54
- ret[:title] = array(ret[:title])
55
- ret[:title] = ret[:title].reduce([]) do |a, t|
56
- if t.is_a?(String)
57
- a << split_title(t)
58
- elsif t.is_a?(Hash) && t[:type]
59
- idx = a.index { |i| i[:language] == t[:language] }
60
- title_key = t[:type].sub("-", "_").to_sym
61
- if idx
62
- a[idx][title_key] = t[:content]
63
- a
64
- else
65
- a << { title_key => t[:content], language: t[:language], script: t[:script] }
66
- end
67
- elsif t.is_a?(Hash) && t[:content]
68
- a << split_title(t[:content], t[:language], t[:script])
69
- end
70
- end
71
- end
72
-
73
6
  #
74
7
  # Ovverides superclass's method
75
8
  #
@@ -83,9 +16,9 @@ module RelatonIsoBib
83
16
  # Ovverides superclass's method
84
17
  #
85
18
  # @param title [Hash]
86
- # @return [RelatonIsoBib::TypedTitleString]
19
+ # @return [RelatonBib::TypedTitleString]
87
20
  def typed_title_strig(title)
88
- TypedTitleString.new title
21
+ RelatonBib::TypedTitleString.new title
89
22
  end
90
23
 
91
24
  # @param ret [Hash]
@@ -7,7 +7,8 @@ module RelatonIsoBib
7
7
  # @param subgroup [Integer, NilClass]
8
8
  def initialize(code = nil, field: nil, group: nil, subgroup: nil)
9
9
  unless code || field
10
- raise ArgumentError, "wrong arguments (should be string or { fieldcode: [String] }"
10
+ raise ArgumentError,
11
+ "wrong arguments (should be string or { fieldcode: [String] }"
11
12
  end
12
13
 
13
14
  field, group, subgroup = code.split "." if code
@@ -28,5 +29,17 @@ module RelatonIsoBib
28
29
  hash["code"] = code if code
29
30
  hash
30
31
  end
32
+
33
+ # @param prefix [String]
34
+ # @param count [Integer] number of ICS
35
+ # @return [String]
36
+ def to_asciibib(prefix = "", count = 1)
37
+ pref = prefix.empty? ? prefix : prefix + "."
38
+ pref += "ics"
39
+ out = count > 1 ? "#{pref}::\n" : ""
40
+ out += "#{pref}.code:: #{code}\n"
41
+ out += "#{pref}.description:: #{description}\n"
42
+ out
43
+ end
31
44
  end
32
45
  end
@@ -3,7 +3,6 @@
3
3
  require "nokogiri"
4
4
  require "isoics"
5
5
  require "relaton_bib"
6
- require "relaton_iso_bib/typed_title_string"
7
6
  require "relaton_iso_bib/editorial_group"
8
7
  require "relaton_iso_bib/xml_parser"
9
8
  require "relaton_iso_bib/structured_identifier"
@@ -32,7 +31,7 @@ module RelatonIsoBib
32
31
  attr_reader :structuredidentifier
33
32
 
34
33
  # @!attribute [r] title
35
- # @return [Array<RelatonIsoBib::TypedTitleString>]
34
+ # @return [Array<RelatonBib::TypedTitleString>]
36
35
 
37
36
  # @return [String, NilClass]
38
37
  attr_reader :doctype, :stagename
@@ -43,9 +42,6 @@ module RelatonIsoBib
43
42
  # @return [Array<RelatonIsoBib::Ics>]
44
43
  attr_reader :ics
45
44
 
46
- # @return [TrueClass, FalseClass, NilClass]
47
- attr_accessor :all_parts
48
-
49
45
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
50
46
  # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
51
47
 
@@ -76,7 +72,7 @@ module RelatonIsoBib
76
72
  # @option title [String] :language
77
73
  # @option title [String] :script
78
74
  #
79
- # @param editorialgroup [Hash, RelatonIsoBib::EditorialGroup, RelatonItu::EditorialGroup]
75
+ # @param editorialgroup [Hash, RelatonIsoBib::EditorialGroup]
80
76
  # @option workgrpup [String] :name
81
77
  # @option workgrpup [String] :abbreviation
82
78
  # @option workgrpup [String] :url
@@ -128,27 +124,17 @@ module RelatonIsoBib
128
124
  # @raise [ArgumentError]
129
125
  def initialize(**args)
130
126
  check_doctype args[:doctype]
131
- # check_language args.fetch(:language, [])
132
- # check_script args.fetch(:script, [])
133
127
 
134
128
  super_args = args.select do |k|
135
- %i[id docnumber language script docstatus date abstract contributor
136
- edition version relation biblionote series medium place copyright
137
- link fetched docid formattedref extent accesslocation classification
138
- validity keyword].include? k
129
+ %i[id title docnumber language script docstatus date abstract
130
+ contributor edition version relation biblionote series medium place
131
+ copyright link fetched docid formattedref extent accesslocation
132
+ classification validity doctype keyword].include? k
139
133
  end
140
134
  super super_args
141
135
 
142
136
  @type = args[:type] || "standard"
143
137
 
144
- @title = args.fetch(:title, []).reduce([]) do |a, t|
145
- if t.is_a? Hash
146
- a + typed_titles(t)
147
- else
148
- a << t
149
- end
150
- end
151
-
152
138
  if args[:editorialgroup]
153
139
  @editorialgroup = if args[:editorialgroup].is_a?(Hash)
154
140
  EditorialGroup.new(args[:editorialgroup])
@@ -157,100 +143,26 @@ module RelatonIsoBib
157
143
  end
158
144
 
159
145
  @structuredidentifier = args[:structuredidentifier]
160
- @doctype ||= args[:doctype]
146
+ # @doctype = args[:doctype] || "international-standard"
161
147
  @ics = args.fetch(:ics, []).map { |i| i.is_a?(Hash) ? Ics.new(i) : i }
162
148
  @stagename = args[:stagename]
163
149
  @id_attribute = true
164
150
  end
165
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
166
- # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
167
-
168
- def disable_id_attribute
169
- @id_attribute = false
170
- end
171
-
172
- # remove title part components and abstract
173
- def to_all_parts
174
- me = deep_clone
175
- me.disable_id_attribute
176
- me.relation << RelatonBib::DocumentRelation.new(
177
- type: "instance", bibitem: self,
178
- )
179
- me.language.each do |l|
180
- me.title.delete_if { |t| t.type == "title-part" }
181
- ttl = me.title.select { |t| t.type != "main" && t.title.language.include?(l) }
182
- tm_en = ttl.map { |t| t.title.content }.join " – "
183
- me.title.detect { |t| t.type == "main" && t.title.language.include?(l) }&.title&.content = tm_en
184
- end
185
- me.abstract = []
186
- me.docidentifier.each(&:remove_part)
187
- me.docidentifier.each(&:all_parts)
188
- me.structuredidentifier.remove_part
189
- me.structuredidentifier.all_parts
190
- me.docidentifier.each &:remove_date
191
- me.structuredidentifier&.remove_date
192
- me.all_parts = true
193
- me
194
- end
195
-
196
- def abstract=(value)
197
- @abstract = value
198
- end
199
-
200
- def deep_clone
201
- dump = Marshal.dump self
202
- Marshal.load dump
203
- end
204
151
 
205
- # convert ISO:yyyy reference to reference to most recent
206
- # instance of reference, removing date-specific infomration:
207
- # date of publication, abstracts. Make dated reference Instance relation
208
- # of the redacated document
209
- def to_most_recent_reference
210
- me = deep_clone
211
- self.disable_id_attribute
212
- me.relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: self)
213
- me.abstract = []
214
- me.date = []
215
- me.docidentifier.each &:remove_date
216
- me.structuredidentifier&.remove_date
217
- me.id&.sub! /-[12]\d\d\d/, ""
218
- me
219
- end
220
-
221
- # @param lang [String] language code Iso639
222
- # @return [Array<RelatonIsoBib::TypedTitleString>]
223
- def title(lang: nil)
224
- if lang
225
- @title.select { |t| t.title.language.include? lang }
226
- else
227
- @title
228
- end
229
- end
230
-
231
- # @param type [Symbol] type of url, can be :src/:obp/:rss
232
- # @return [String]
233
- def url(type = :src)
234
- @link.detect { |s| s.type == type.to_s }.content.to_s
235
- end
236
-
237
- # @return [String]
238
- def to_xml(builder = nil, **opts, &block)
239
- if opts[:note]&.any?
240
- opts.fetch(:note, []).each do |n|
241
- @biblionote << RelatonBib::BiblioNote.new(
242
- content: n[:text], type: n[:type], format: "text/plain",
243
- )
244
- end
245
- end
246
- super builder, **opts do |b|
152
+ # @param opts [Hash]
153
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
154
+ # @option opts [Boolean] :bibdata
155
+ # @option opts [String] :lang language
156
+ # @return [String] XML
157
+ def to_xml(**opts)
158
+ super **opts do |b|
247
159
  if opts[:bibdata] && (doctype || respond_to?(:committee) && committee ||
248
160
  editorialgroup || ics.any? || structuredidentifier || stagename ||
249
161
  block_given?)
250
162
  b.ext do
251
163
  b.doctype doctype if doctype
252
164
  b.docsubtype docsubtype if respond_to?(:docsubtype) && docsubtype
253
- # GB renders gbcommittee elements istead of an editorialgroup element.
165
+ # GB renders gbcommittee elements istead of an editorialgroup
254
166
  if respond_to? :committee
255
167
  committee&.to_xml b
256
168
  else
@@ -265,36 +177,26 @@ module RelatonIsoBib
265
177
  end
266
178
  end
267
179
 
180
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
181
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
182
+
268
183
  # @return [Hash]
269
184
  def to_hash
270
185
  hash = super
271
- hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup
272
- hash["ics"] = single_element_array(ics) if ics&.any?
273
- hash["structuredidentifier"] = structuredidentifier.to_hash if structuredidentifier
274
- hash["doctype"] = doctype if doctype
275
186
  hash["stagename"] = stagename if stagename
276
187
  hash
277
188
  end
278
189
 
279
- private
280
-
281
- # @param language [Array<String>]
282
- # @raise ArgumentError
283
- # def check_language(language)
284
- # language.each do |lang|
285
- # unless %w[en fr].include? lang
286
- # raise ArgumentError, "invalid language: #{lang}"
287
- # end
288
- # end
289
- # end
190
+ # @param prefix [String]
191
+ # @return [String]
192
+ def to_asciibib(prefix = "")
193
+ pref = prefix.empty? ? prefix : prefix + "."
194
+ out = super
195
+ out += "#{pref}stagename:: #{stagename}\n" if stagename
196
+ out
197
+ end
290
198
 
291
- # @param script [Array<String>]
292
- # @raise ArgumentError
293
- # def check_script(script)
294
- # script.each do |scr|
295
- # raise ArgumentError, "invalid script: #{scr}" unless scr == "Latn"
296
- # end
297
- # end
199
+ private
298
200
 
299
201
  # @param doctype [String]
300
202
  # @raise ArgumentError
@@ -304,64 +206,17 @@ module RelatonIsoBib
304
206
  end
305
207
  end
306
208
 
307
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
308
-
309
- # @param title [Hash]
310
- # @option title [String] :title_intro
311
- # @option title [String] :title_main
312
- # @option title [String] :title_part
313
- # @option title [String] :language
314
- # @option title [String] :script
315
- # @return [Array<RelatonIsoBib::TypedTitleStrig>]
316
- def typed_titles(title)
317
- titles = []
318
- if title[:title_intro]
319
- titles << TypedTitleString.new(
320
- type: "title-intro", content: title[:title_intro],
321
- language: title[:language], script: title[:script], format: "text/plain",
322
- )
323
- end
324
-
325
- if title[:title_main]
326
- titles << TypedTitleString.new(
327
- type: "title-main", content: title[:title_main],
328
- language: title[:language], script: title[:script], format: "text/plain",
329
- )
330
- end
331
-
332
- if title[:title_part]
333
- titles << TypedTitleString.new(
334
- type: "title-part", content: title[:title_part],
335
- language: title[:language], script: title[:script], format: "text/plain",
336
- )
337
- end
338
-
339
- unless titles.empty?
340
- titles << TypedTitleString.new(
341
- type: "main", content: titles.map { |t| t.title.content }.join(" – "),
342
- language: title[:language], script: title[:script], format: "text/plain",
343
- )
344
- end
345
-
346
- titles
347
- end
348
-
349
- def makeid(id, attribute, _delim = "")
209
+ def makeid(id, attribute, _delim = "") # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
350
210
  return nil if attribute && !@id_attribute
351
211
 
352
212
  id ||= @docidentifier.reject { |i| i&.type == "DOI" }[0]
353
- # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/'
354
- # idstr = "#{contribs}#{delim}#{id.project_number}"
355
- # idstr = id.project_number.to_s
356
213
  if id
357
214
  idstr = id.id
358
215
  idstr = "IEV" if structuredidentifier&.project_number == "IEV"
359
216
  else
360
217
  idstr = formattedref&.content
361
218
  end
362
- # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
363
219
  idstr&.gsub(/:/, "-")&.gsub(/\s/, "")&.strip
364
220
  end
365
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
366
221
  end
367
222
  end