relaton-iso-bib 1.0.0 → 1.3.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.
@@ -91,6 +91,12 @@
91
91
  </define>
92
92
  <define name="sections">
93
93
  <element name="sections">
94
+ <zeroOrMore>
95
+ <choice>
96
+ <ref name="note"/>
97
+ <ref name="admonition"/>
98
+ </choice>
99
+ </zeroOrMore>
94
100
  <ref name="clause"/>
95
101
  <optional>
96
102
  <choice>
@@ -263,6 +269,8 @@
263
269
  <value>publicly-available-specification</value>
264
270
  <value>international-workshop-agreement</value>
265
271
  <value>guide</value>
272
+ <value>amendment</value>
273
+ <value>technical-corrigendum</value>
266
274
  </choice>
267
275
  </define>
268
276
  <define name="structuredidentifier">
@@ -354,6 +362,9 @@
354
362
  <data type="boolean"/>
355
363
  </attribute>
356
364
  </optional>
365
+ <optional>
366
+ <attribute name="number"/>
367
+ </optional>
357
368
  <optional>
358
369
  <attribute name="subsequence"/>
359
370
  </optional>
@@ -510,7 +521,7 @@
510
521
  </attribute>
511
522
  </optional>
512
523
  <oneOrMore>
513
- <ref name="paragraph-with-footnote"/>
524
+ <ref name="BasicBlock"/>
514
525
  </oneOrMore>
515
526
  </element>
516
527
  </define>
@@ -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
37
37
  @technical_committee = technical_committee.map do |tc|
38
38
  tc.is_a?(Hash) ? IsoSubgroup.new(tc) : tc
39
39
  end
@@ -49,8 +49,9 @@ module RelatonIsoBib
49
49
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
50
50
 
51
51
  # @param builder [Nokogiri::XML::Builder]
52
- def to_xml(builder)
53
- return unless technical_committee || subcommittee || workgroup || secretariat
52
+ def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
53
+ return unless technical_committee || subcommittee || workgroup ||
54
+ secretariat
54
55
 
55
56
  builder.editorialgroup do
56
57
  technical_committee.each do |tc|
@@ -69,12 +70,36 @@ module RelatonIsoBib
69
70
 
70
71
  # @return [Hash]
71
72
  def to_hash
72
- hash = { "technical_committee" => single_element_array(technical_committee) }
73
- hash["subcommittee"] = single_element_array(subcommittee) if subcommittee&.any?
73
+ hash = {
74
+ "technical_committee" => single_element_array(technical_committee),
75
+ }
76
+ if subcommittee&.any?
77
+ hash["subcommittee"] = single_element_array(subcommittee)
78
+ end
74
79
  hash["workgroup"] = single_element_array(workgroup) if workgroup&.any?
75
80
  hash["secretariat"] = secretariat if secretariat
76
81
  hash
77
82
  end
83
+
84
+ # @param prefix [String]
85
+ # @return [String]
86
+ def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
87
+ pref = prefix.empty? ? prefix : prefix + "."
88
+ pref += "editorialgroup"
89
+ out = ""
90
+ technical_committee.each do |tc|
91
+ out += tc.to_asciibib "#{pref}.technical_committee",
92
+ technical_committee.size
93
+ end
94
+ subcommittee.each do |sc|
95
+ out += sc.to_asciibib "#{pref}.subcommittee", subcommittee.size
96
+ end
97
+ workgroup.each do |wg|
98
+ out += wg.to_asciibib "#{pref}.workgroup", workgroup.size
99
+ end
100
+ out += "#{pref}.secretariat:: #{secretariat}\n" if secretariat
101
+ out
102
+ end
78
103
  end
79
104
 
80
105
  # ISO subgroup.
@@ -111,5 +136,15 @@ module RelatonIsoBib
111
136
  hash["number"] = number if number
112
137
  hash
113
138
  end
139
+
140
+ # @param prefix [String]
141
+ # @param count [Integer] number of the elements
142
+ def to_asciibib(prefix, count = 1)
143
+ out = count > 1 ? "#{prefix}::\n" : ""
144
+ out += "#{prefix}.type:: #{type}\n" if type
145
+ out += "#{prefix}.number:: #{number}\n" if number
146
+ out += "#{prefix}.name:: #{name}\n"
147
+ out
148
+ end
114
149
  end
115
150
  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"
@@ -23,19 +22,19 @@ module RelatonIsoBib
23
22
  # Bibliographic item.
24
23
  class IsoBibliographicItem < RelatonBib::BibliographicItem
25
24
  TYPES = %w[
26
- standard
27
25
  international-standard technical-specification technical-report
28
26
  publicly-available-specification international-workshop-agreement guide
27
+ amendment technical-corrigendum
29
28
  ].freeze
30
29
 
31
30
  # @return [RelatonIsoBib::StructuredIdentifier]
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
- attr_reader :doctype
37
+ attr_reader :doctype, :stagename
39
38
 
40
39
  # @return [RelatonIsoBib::EditorialGroup]
41
40
  attr_reader :editorialgroup
@@ -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
 
@@ -67,6 +63,7 @@ module RelatonIsoBib
67
63
  # @param validity [RelatonBib:Validity, NilClass]
68
64
  # @param docid [Array<RelatonBib::DocumentIdentifier>]
69
65
  # @param structuredidentifier [RelatonIsoBib::StructuredIdentifier]
66
+ # @param stagename [String, NilClass]
70
67
  #
71
68
  # @param title [Array<Hash>]
72
69
  # @option title [String] :title_intro
@@ -75,7 +72,7 @@ module RelatonIsoBib
75
72
  # @option title [String] :language
76
73
  # @option title [String] :script
77
74
  #
78
- # @param editorialgroup [Hash, RelatonIsoBib::EditorialGroup, RelatonItu::EditorialGroup]
75
+ # @param editorialgroup [Hash, RelatonIsoBib::EditorialGroup]
79
76
  # @option workgrpup [String] :name
80
77
  # @option workgrpup [String] :abbreviation
81
78
  # @option workgrpup [String] :url
@@ -127,24 +124,23 @@ module RelatonIsoBib
127
124
  # @raise [ArgumentError]
128
125
  def initialize(**args)
129
126
  check_doctype args[:doctype]
130
- # check_language args.fetch(:language, [])
131
- # check_script args.fetch(:script, [])
132
127
 
133
128
  super_args = args.select do |k|
134
129
  %i[id docnumber language script docstatus date abstract contributor
135
130
  edition version relation biblionote series medium place copyright
136
131
  link fetched docid formattedref extent accesslocation classification
137
- validity keyword].include? k
132
+ validity doctype keyword].include? k
138
133
  end
139
134
  super super_args
140
135
 
141
136
  @type = args[:type] || "standard"
142
137
 
143
- @title = args.fetch(:title, []).reduce([]) do |a, t|
138
+ @title = args.fetch(:title, []).map do |t|
144
139
  if t.is_a? Hash
145
- a + typed_titles(t)
140
+ # a + typed_titles(t)
141
+ RelatonBib::TypedTitleString.new t
146
142
  else
147
- a << t
143
+ t
148
144
  end
149
145
  end
150
146
 
@@ -156,98 +152,29 @@ module RelatonIsoBib
156
152
  end
157
153
 
158
154
  @structuredidentifier = args[:structuredidentifier]
159
- @doctype ||= args[:doctype]
155
+ # @doctype = args[:doctype] || "international-standard"
160
156
  @ics = args.fetch(:ics, []).map { |i| i.is_a?(Hash) ? Ics.new(i) : i }
157
+ @stagename = args[:stagename]
161
158
  @id_attribute = true
162
159
  end
163
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
164
- # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
165
-
166
- def disable_id_attribute
167
- @id_attribute = false
168
- end
169
-
170
- # remove title part components and abstract
171
- def to_all_parts
172
- me = deep_clone
173
- me.disable_id_attribute
174
- me.relation << RelatonBib::DocumentRelation.new(
175
- type: "instance", bibitem: self,
176
- )
177
- me.language.each do |l|
178
- me.title.delete_if { |t| t.type == "title-part" }
179
- ttl = me.title.select { |t| t.type != "main" && t.title.language.include?(l) }
180
- tm_en = ttl.map { |t| t.title.content }.join " – "
181
- me.title.detect { |t| t.type == "main" && t.title.language.include?(l) }&.title&.content = tm_en
182
- end
183
- me.abstract = []
184
- me.docidentifier.each(&:remove_part)
185
- me.docidentifier.each(&:all_parts)
186
- me.structuredidentifier.remove_part
187
- me.structuredidentifier.all_parts
188
- me.docidentifier.each &:remove_date
189
- me.structuredidentifier&.remove_date
190
- me.all_parts = true
191
- me
192
- end
193
-
194
- def abstract=(value)
195
- @abstract = value
196
- end
197
-
198
- def deep_clone
199
- dump = Marshal.dump self
200
- Marshal.load dump
201
- end
202
-
203
- # convert ISO:yyyy reference to reference to most recent
204
- # instance of reference, removing date-specific infomration:
205
- # date of publication, abstracts. Make dated reference Instance relation
206
- # of the redacated document
207
- def to_most_recent_reference
208
- me = deep_clone
209
- self.disable_id_attribute
210
- me.relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: self)
211
- me.abstract = []
212
- me.date = []
213
- me.docidentifier.each &:remove_date
214
- me.structuredidentifier&.remove_date
215
- me.id&.sub! /-[12]\d\d\d/, ""
216
- me
217
- end
218
160
 
219
- # @param lang [String] language code Iso639
220
- # @return [Array<RelatonIsoBib::TypedTitleString>]
221
- def title(lang: nil)
222
- if lang
223
- @title.select { |t| t.title.language.include? lang }
224
- else
225
- @title
226
- end
227
- end
228
-
229
- # @param type [Symbol] type of url, can be :src/:obp/:rss
230
161
  # @return [String]
231
- def url(type = :src)
232
- @link.detect { |s| s.type == type.to_s }.content.to_s
233
- end
234
-
235
- # @return [String]
236
- def to_xml(builder = nil, **opts, &block)
162
+ def to_xml(builder = nil, **opts)
237
163
  if opts[:note]&.any?
238
164
  opts.fetch(:note, []).each do |n|
239
165
  @biblionote << RelatonBib::BiblioNote.new(
240
- content: n[:text], type: n[:type], format: "text/plain",
166
+ content: n[:text], type: n[:type], format: "text/plain"
241
167
  )
242
168
  end
243
169
  end
244
170
  super builder, **opts do |b|
245
171
  if opts[:bibdata] && (doctype || respond_to?(:committee) && committee ||
246
- editorialgroup || ics.any? || structuredidentifier || block_given?)
172
+ editorialgroup || ics.any? || structuredidentifier || stagename ||
173
+ block_given?)
247
174
  b.ext do
248
175
  b.doctype doctype if doctype
249
176
  b.docsubtype docsubtype if respond_to?(:docsubtype) && docsubtype
250
- # GB renders gbcommittee elements istead of an editorialgroup element.
177
+ # GB renders gbcommittee elements istead of an editorialgroup
251
178
  if respond_to? :committee
252
179
  committee&.to_xml b
253
180
  else
@@ -255,41 +182,33 @@ module RelatonIsoBib
255
182
  end
256
183
  ics.each { |i| i.to_xml b }
257
184
  structuredidentifier&.to_xml b
185
+ b.stagename stagename if stagename
258
186
  yield b if block_given?
259
187
  end
260
188
  end
261
189
  end
262
190
  end
263
191
 
192
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
193
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
194
+
264
195
  # @return [Hash]
265
196
  def to_hash
266
197
  hash = super
267
- hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup
268
- hash["ics"] = single_element_array(ics) if ics&.any?
269
- hash["structuredidentifier"] = structuredidentifier.to_hash if structuredidentifier
270
- hash["doctype"] = doctype if doctype
198
+ hash["stagename"] = stagename if stagename
271
199
  hash
272
200
  end
273
201
 
274
- private
275
-
276
- # @param language [Array<String>]
277
- # @raise ArgumentError
278
- # def check_language(language)
279
- # language.each do |lang|
280
- # unless %w[en fr].include? lang
281
- # raise ArgumentError, "invalid language: #{lang}"
282
- # end
283
- # end
284
- # end
202
+ # @param prefix [String]
203
+ # @return [String]
204
+ def to_asciibib(prefix = "")
205
+ pref = prefix.empty? ? prefix : prefix + "."
206
+ out = super
207
+ out += "#{pref}stagename:: #{stagename}\n" if stagename
208
+ out
209
+ end
285
210
 
286
- # @param script [Array<String>]
287
- # @raise ArgumentError
288
- # def check_script(script)
289
- # script.each do |scr|
290
- # raise ArgumentError, "invalid script: #{scr}" unless scr == "Latn"
291
- # end
292
- # end
211
+ private
293
212
 
294
213
  # @param doctype [String]
295
214
  # @raise ArgumentError
@@ -299,64 +218,17 @@ module RelatonIsoBib
299
218
  end
300
219
  end
301
220
 
302
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
303
-
304
- # @param title [Hash]
305
- # @option title [String] :title_intro
306
- # @option title [String] :title_main
307
- # @option title [String] :title_part
308
- # @option title [String] :language
309
- # @option title [String] :script
310
- # @return [Array<RelatonIsoBib::TypedTitleStrig>]
311
- def typed_titles(title)
312
- titles = []
313
- if title[:title_intro]
314
- titles << TypedTitleString.new(
315
- type: "title-intro", content: title[:title_intro],
316
- language: title[:language], script: title[:script], format: "text/plain",
317
- )
318
- end
319
-
320
- if title[:title_main]
321
- titles << TypedTitleString.new(
322
- type: "title-main", content: title[:title_main],
323
- language: title[:language], script: title[:script], format: "text/plain",
324
- )
325
- end
326
-
327
- if title[:title_part]
328
- titles << TypedTitleString.new(
329
- type: "title-part", content: title[:title_part],
330
- language: title[:language], script: title[:script], format: "text/plain",
331
- )
332
- end
333
-
334
- unless titles.empty?
335
- titles << TypedTitleString.new(
336
- type: "main", content: titles.map { |t| t.title.content }.join(" – "),
337
- language: title[:language], script: title[:script], format: "text/plain",
338
- )
339
- end
340
-
341
- titles
342
- end
343
-
344
- def makeid(id, attribute, _delim = "")
221
+ def makeid(id, attribute, _delim = "") # rubocop:disable Metrics/CyclomaticComplexity
345
222
  return nil if attribute && !@id_attribute
346
223
 
347
224
  id ||= @docidentifier.reject { |i| i&.type == "DOI" }[0]
348
- # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/'
349
- # idstr = "#{contribs}#{delim}#{id.project_number}"
350
- # idstr = id.project_number.to_s
351
225
  if id
352
226
  idstr = id.id
353
227
  idstr = "IEV" if structuredidentifier&.project_number == "IEV"
354
228
  else
355
229
  idstr = formattedref&.content
356
230
  end
357
- # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
358
231
  idstr&.gsub(/:/, "-")&.gsub(/\s/, "")&.strip
359
232
  end
360
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
361
233
  end
362
234
  end