relaton-iso-bib 1.0.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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>
@@ -247,7 +253,7 @@
247
253
  <define name="preface">
248
254
  <element name="preface">
249
255
  <optional>
250
- <ref name="preface_abstract"/>
256
+ <ref name="abstract"/>
251
257
  </optional>
252
258
  <ref name="foreword"/>
253
259
  <optional>
@@ -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,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"
@@ -23,16 +22,16 @@ 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
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,24 +124,23 @@ 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
129
  %i[id docnumber language script docstatus date abstract contributor
136
130
  edition version relation biblionote series medium place copyright
137
131
  link fetched docid formattedref extent accesslocation classification
138
- validity keyword].include? k
132
+ 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|
138
+ @title = args.fetch(:title, []).map do |t|
145
139
  if t.is_a? Hash
146
- a + typed_titles(t)
140
+ # a + typed_titles(t)
141
+ RelatonBib::TypedTitleString.new t
147
142
  else
148
- a << t
143
+ t
149
144
  end
150
145
  end
151
146
 
@@ -157,92 +152,14 @@ module RelatonIsoBib
157
152
  end
158
153
 
159
154
  @structuredidentifier = args[:structuredidentifier]
160
- @doctype ||= args[:doctype]
155
+ # @doctype = args[:doctype] || "international-standard"
161
156
  @ics = args.fetch(:ics, []).map { |i| i.is_a?(Hash) ? Ics.new(i) : i }
162
157
  @stagename = args[:stagename]
163
158
  @id_attribute = true
164
159
  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
-
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
160
 
237
161
  # @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
162
+ def to_xml(builder = nil, **opts)
246
163
  super builder, **opts do |b|
247
164
  if opts[:bibdata] && (doctype || respond_to?(:committee) && committee ||
248
165
  editorialgroup || ics.any? || structuredidentifier || stagename ||
@@ -250,7 +167,7 @@ module RelatonIsoBib
250
167
  b.ext do
251
168
  b.doctype doctype if doctype
252
169
  b.docsubtype docsubtype if respond_to?(:docsubtype) && docsubtype
253
- # GB renders gbcommittee elements istead of an editorialgroup element.
170
+ # GB renders gbcommittee elements istead of an editorialgroup
254
171
  if respond_to? :committee
255
172
  committee&.to_xml b
256
173
  else
@@ -265,36 +182,26 @@ module RelatonIsoBib
265
182
  end
266
183
  end
267
184
 
185
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
186
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
187
+
268
188
  # @return [Hash]
269
189
  def to_hash
270
190
  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
191
  hash["stagename"] = stagename if stagename
276
192
  hash
277
193
  end
278
194
 
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
195
+ # @param prefix [String]
196
+ # @return [String]
197
+ def to_asciibib(prefix = "")
198
+ pref = prefix.empty? ? prefix : prefix + "."
199
+ out = super
200
+ out += "#{pref}stagename:: #{stagename}\n" if stagename
201
+ out
202
+ end
290
203
 
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
204
+ private
298
205
 
299
206
  # @param doctype [String]
300
207
  # @raise ArgumentError
@@ -304,64 +211,17 @@ module RelatonIsoBib
304
211
  end
305
212
  end
306
213
 
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 = "")
214
+ def makeid(id, attribute, _delim = "") # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
350
215
  return nil if attribute && !@id_attribute
351
216
 
352
217
  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
218
  if id
357
219
  idstr = id.id
358
220
  idstr = "IEV" if structuredidentifier&.project_number == "IEV"
359
221
  else
360
222
  idstr = formattedref&.content
361
223
  end
362
- # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
363
224
  idstr&.gsub(/:/, "-")&.gsub(/\s/, "")&.strip
364
225
  end
365
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
366
226
  end
367
227
  end