relaton-bib 0.9.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 103eab0d5c12a5bdb75281aebd1f59ad96e81da707f69c09355d9bf05f841f1a
4
- data.tar.gz: 3c51acb08e97d791e977a6752db949683f67e60e8402f7d0c6d3aa43ac4c4d95
3
+ metadata.gz: 2cf0aacc339840ecc4607d6b87e625eaef60ba12ab0fbeffba5876898518f138
4
+ data.tar.gz: e41a599b99baaa6d1002cd3ad13803bcffeaa6949840a8cd757db3689716f06b
5
5
  SHA512:
6
- metadata.gz: c1c9e8003d2f2c859a6600381955e61f3bdc540a1504b17eda23cfce99271b657e178173d123f89cafff8eadb19c5dd3a67c89714ecb83035d40053debaaadb6
7
- data.tar.gz: f9607f2ff6b590a10b190e00d1e512148ecbfe9ad60b7a7e1dbea3ae032617817a6aa1dd4836b5cf10ffbb497792639ab1a3ea8496d13518f81fc59df84e08c4
6
+ metadata.gz: 4f8e1bfe3c6ca8d2ec19733f7ea0f018bae2a102ad92d05bb0983ddf9b7e8715c86c56980ffa106500c2a6971a625143cb6bec2ae9b9a2dd0190fc8b605539c1
7
+ data.tar.gz: 721ba6235c7cabc380825ce184f0b2874f1ba519b2f6b9dc44fea52ae061b3bdd18ab56c5db94698535b8db10fe365a88aaf23bcd32a25fa5ce7de96bb8a93b6
@@ -0,0 +1,2 @@
1
+ rubocop:
2
+ config_file: .rubocop.yml
@@ -155,8 +155,16 @@ item = RelatonBib::BibliographicItem.new(
155
155
  bibitem: RelatonBib::BibliographicItem.new(
156
156
  formattedref: RelatonBib::FormattedRef.new(content: "ISO 19115:2003"),
157
157
  ),
158
- bib_locality: [
159
- RelatonBib::BibItemLocality.new("section", "Reference from"),
158
+ locality: [
159
+ RelatonBib::LocalityStack.new([
160
+ RelatonBib::Locality.new("volume", "1"),
161
+ RelatonBib::Locality.new("section", "2"),
162
+ ]),
163
+ ],
164
+ source_locality: [
165
+ RelatonBib::SourceLocalityStack.new([
166
+ RelatonBib::SourceLocality.new("chapter", "4"),
167
+ ]),
160
168
  ],
161
169
  },
162
170
  {
@@ -249,7 +257,6 @@ item.abstract
249
257
 
250
258
  item.abstract(lang: "en").to_s
251
259
  => "ISO 19115-1:2014 defines the schema required for ..."
252
- "
253
260
  ----
254
261
 
255
262
  === BibliographicItem references
@@ -274,11 +281,11 @@ item.to_xml
274
281
  ----
275
282
 
276
283
  Default root element is `bibitem`. With argument `bibdata: true` the XML wrapped with `bibdata` element.
277
- [source,ruby]
278
284
 
285
+ [source,ruby]
279
286
  ----
280
- item.to_xml
281
- => "<bibitem id=\"ISO/TC211\" type=\"standard\">
287
+ item.to_xml bibdata: true
288
+ => "<bibdata type=\"standard\">
282
289
  <fetched>2019-04-30</fetched>
283
290
  <title type=\"main\" language=\"en\" script=\"Latn\">Geographic information</title>
284
291
  ...
@@ -288,8 +295,8 @@ item.to_xml
288
295
  ==== Date format
289
296
 
290
297
  By default date elements are formatted as year (yyyy). Option `:date_format` allows to output date elements in `:short` (yyyy-mm) and `:full` (yyyy-mm-dd) additiona formats.
291
- [surce,ruby]
292
298
 
299
+ [surce,ruby]
293
300
  ----
294
301
  item.to_xml date_format: :short
295
302
  => "<bibitem id=\"ISO/TC211\" type=\"standard\">
@@ -2,24 +2,24 @@
2
2
 
3
3
  == YAML
4
4
 
5
- The following structure is in place for encoding bibitem as YAML objects, and is also used
6
- to represent bibliographic entries in Metanorma Asciidoctor. The structure has not yet been
5
+ The following structure is in place for encoding bibitem as YAML objects, and is also used
6
+ to represent bibliographic entries in Metanorma AsciiDoc. The structure has not yet been
7
7
  generalised to `bibdata/ext`, the flavour-specific extensions of relaton.
8
8
 
9
9
  If an element in Relaton XML has attributes, the content of the element is represented in YAML
10
10
  with a `content` key:
11
11
 
12
12
  [source,xml]
13
- ....
13
+ ----
14
14
  <title type="main">Geographic information</title>
15
- ....
15
+ ----
16
16
 
17
17
  [source,yaml]
18
- ....
18
+ ----
19
19
  title:
20
20
  type: main
21
21
  content: Geographic information
22
- ....
22
+ ----
23
23
 
24
24
  Any elements with a cardinality of many can be represented as arrays, but
25
25
  they can also be populated by a hash or single element. For example,
@@ -27,7 +27,7 @@ a Relaton title can have multiple titles, and multiple scripts; so
27
27
  the following are equivalent:
28
28
 
29
29
  [source,yaml]
30
- ....
30
+ ----
31
31
  title:
32
32
  - type: main
33
33
  content: Geographic information
@@ -37,7 +37,7 @@ title:
37
37
  script:
38
38
  - Latn
39
39
  script: Latn
40
- ....
40
+ ----
41
41
 
42
42
  In YAML, "on" is a reserved word, and thus cannot be used as a key. "value" is used as a synonym for
43
43
  "on" in dates.
@@ -45,7 +45,7 @@ In YAML, "on" is a reserved word, and thus cannot be used as a key. "value" is u
45
45
  The structure below is given in YAML format:
46
46
 
47
47
  [source,yaml]
48
- ....
48
+ ----
49
49
  # bibliographic item anchor, used to crossreference within document
50
50
  id: ISO/TC211
51
51
  # date record was created
@@ -118,11 +118,11 @@ abstract:
118
118
  # Initials, forename, additions, prefixes are arrays.
119
119
  # Name field values are either strings, or hashes, with content and language and script attributes.
120
120
  # The language and script attribute can also be given on the name.
121
- # Contacts are an array, containing either addresses, or other fields.
122
- # Addresses are identified as hashes containing a city attribute; they can also contain a street
121
+ # Contacts are an array, containing either addresses, or other fields.
122
+ # Addresses are identified as hashes containing a city attribute; they can also contain a street
123
123
  # (which is an array), a postcode, a state, and a country. The other contact fields
124
124
  # are phones, emails, uris; they contain a type giving the field name, and a value.
125
- # Affiliations are an array, and they contains an organization, and an optional description.
125
+ # Affiliations are an array, and they contains an organization, and an optional description.
126
126
  # The affiliation description can be a single string, or a hash of content, language, script, and format.
127
127
  contributor:
128
128
  - organization:
@@ -130,7 +130,7 @@ contributor:
130
130
  url: www.iso.org
131
131
  abbreviation: ISO
132
132
  subdivision: division
133
- role:
133
+ role:
134
134
  type: publisher
135
135
  description: Publisher role
136
136
  - person:
@@ -142,7 +142,7 @@ contributor:
142
142
  - organization:
143
143
  name: IETF
144
144
  abbreviation: IETF
145
- identifier:
145
+ identifier:
146
146
  - type: uri
147
147
  id: www.ietf.org
148
148
  description: Affiliation description
@@ -181,7 +181,7 @@ contributor:
181
181
  identifier:
182
182
  - type: uri
183
183
  id: www.person.com
184
- role:
184
+ role:
185
185
  author
186
186
  # copyright consists of an owner (a hash containing the fields of an organisation),
187
187
  # a "from" date, and an optional "to" date
@@ -220,7 +220,7 @@ relation:
220
220
  # an abbreviation, a from, a to, a number, and a partnumber.
221
221
  # The series title, like the titles of bibliographic items, contains a type,
222
222
  # content, and optional language, script, and format attributes.
223
- # The abbreviation and formattedref are either a string,
223
+ # The abbreviation and formattedref are either a string,
224
224
  # or a hash containing content, language, and script.
225
225
  series:
226
226
  - type: main
@@ -241,7 +241,7 @@ series:
241
241
  number: serie1234
242
242
  partnumber: part5678
243
243
  - type: alt
244
- formattedref:
244
+ formattedref:
245
245
  content: serieref
246
246
  language: en
247
247
  script: Latn
@@ -269,30 +269,30 @@ validity:
269
269
  begins: 2010-10-10 12:21
270
270
  ends: 2011-02-03 18:30
271
271
  revision: 2011-03-04 09:00
272
- ....
272
+ ----
273
273
 
274
274
  == Metanorma structure (AsciiBib): nested definition list
275
275
 
276
- The Metanorma Asciidoctor representation of the Relaton hash structure
276
+ The Metanorma AsciiDoc representation of the Relaton hash structure
277
277
  in a bibliography
278
278
  is as a definition list of element name and element contents,
279
279
  with nested definition lists for nested structures. If a nested
280
280
  definition is given for an element, the element itself has a blank definition.
281
281
 
282
- As with the YAML representation, if an element in Relaton XML has attributes,
282
+ As with the YAML representation, if an element in Relaton XML has attributes,
283
283
  the content of the element is represented in YAML with a `content` key:
284
284
 
285
285
  [source,xml]
286
- ....
286
+ ----
287
287
  <title type="main">Geographic information</title>
288
- ....
288
+ ----
289
289
 
290
290
  [source,asciidoc]
291
- ....
291
+ ----
292
292
  title::
293
293
  type::: main
294
294
  content::: Geographic information
295
- ....
295
+ ----
296
296
 
297
297
  Likewise, as with the YAML representation,
298
298
  Repeating elements in a hash can be realised as ordered or unordered lists.
@@ -304,9 +304,9 @@ language::
304
304
  . fr
305
305
  ----
306
306
 
307
- Metanorma Asciidoctor also supports representing repeating elements
307
+ Metanorma AsciiDoc also supports representing repeating elements
308
308
  by repeating the key for that entry. This will almost always be more
309
- straightforward to use in Asciidoctor:
309
+ straightforward to use in AsciiDoc:
310
310
 
311
311
  [source,asciidoc]
312
312
  ----
@@ -314,19 +314,19 @@ language:: en
314
314
  language:: fr
315
315
  ----
316
316
 
317
- Each Relaton entry in a bibliography is represented in Metanorma Asciidoctor
317
+ Each Relaton entry in a bibliography is represented in Metanorma AsciiDoc
318
318
  through a subclause with option attribute `[%bibitem]`. Any title given to the
319
319
  subclause is treated as the title for the bibliographic entry, with language `en`,
320
- script `Latn`, format `text/plain`, and type `main`.
320
+ script `Latn`, format `text/plain`, and type `main`.
321
321
 
322
- So the following is a very simple reference in Metanorma Asciidoctor:
322
+ So the following is a very simple reference in Metanorma AsciiDoc:
323
323
 
324
324
  [source,asciidoc]
325
325
  ----
326
326
  [%bibitem]
327
327
  === Rubber latex -- Sampling
328
328
  id:: iso123
329
- docid::
329
+ docid::
330
330
  type::: ISO
331
331
  id::: ISO 123
332
332
  docid::
@@ -355,7 +355,7 @@ content::: Latex de caoutchouc -- Échantillonnage
355
355
  Note the use of `content` as a key to represent the contents of the `title` tag.
356
356
 
357
357
  The anchor crossreference for the bibliographic entry may be encoded as either the
358
- `id` entry in the definition list, or as the normal Asciidoctor anchor on the
358
+ `id` entry in the definition list, or as the normal AsciiDoc anchor on the
359
359
  subclause, which takes priority:
360
360
 
361
361
  [source,asciidoc]
@@ -363,7 +363,7 @@ subclause, which takes priority:
363
363
  [[iso123]]
364
364
  [%bibitem]
365
365
  === Rubber latex -- Sampling
366
- docid::
366
+ docid::
367
367
  type::: ISO
368
368
  id::: ISO 123
369
369
  type:: standard
@@ -376,7 +376,7 @@ Repeating elements in a hash can be realised as ordered or unordered lists.
376
376
  [[iso123]]
377
377
  [%bibitem]
378
378
  === Rubber latex -- Sampling
379
- docid::
379
+ docid::
380
380
  type::: ISO
381
381
  id::: ISO 123
382
382
  language::
@@ -384,23 +384,23 @@ language::
384
384
  . fr
385
385
  ----
386
386
 
387
- Metanorma Asciidoctor also supports representing repeating elements
387
+ Metanorma AsciiDoc also supports representing repeating elements
388
388
  by repeating the key for that entry. This will almost always be more
389
- straightforward to use in Asciidoctor:
389
+ straightforward to use in AsciiDoc:
390
390
 
391
391
  [source,asciidoc]
392
392
  ----
393
393
  [[iso123]]
394
394
  [%bibitem]
395
395
  === Rubber latex -- Sampling
396
- docid::
396
+ docid::
397
397
  type::: ISO
398
398
  id::: ISO 123
399
399
  language:: en
400
400
  language:: fr
401
401
  ----
402
402
 
403
- Asciidoctor does not recognise definition lists more than four levels
403
+ AsciiDoc does not recognise definition lists more than four levels
404
404
  deep. If deeper nesting is needed, you will need to attach a new definition
405
405
  list with a list continuation, with the definition list depth reset back to one:
406
406
 
@@ -409,7 +409,7 @@ list with a list continuation, with the definition list depth reset back to one:
409
409
  [[iso123]]
410
410
  [%bibitem]
411
411
  === Rubber latex -- Sampling
412
- docid::
412
+ docid::
413
413
  type::: ISO
414
414
  id::: ISO 123
415
415
  type:: standard
@@ -428,25 +428,25 @@ completename::
428
428
  (This is very awkward, and <<JSONPath>> provides a workaround.)
429
429
 
430
430
  The most heavily nested parts of a Relaton entry are the contributors,
431
- series, and relations.
431
+ series, and relations.
432
432
  Each of these can be marked up as subclauses within the entry, with the clause
433
433
  titles "contributor", "series", and "relation". Each subclause contains
434
434
  a new definition list, with its definition list reset to zero depth;
435
435
  the subclauses can be repeated for multiple instances of the same subentity.
436
436
 
437
- AsciiBib citations can be combined with other Asciidoctor citations in the
438
- same Metanorma document; but any Asciidoctor citations need be precede
437
+ AsciiBib citations can be combined with other AsciiDoc citations in the
438
+ same Metanorma document; but any AsciiDoc citations need be precede
439
439
  AsciiBib citations. Each AsciiBib citations constitutes a subclause of its own,
440
440
  and Metanorma will (unsuccessfully) attempt to incorporate any trailing material
441
- in the subclause, including Asciidoctor citations, into the current AsciiBib
441
+ in the subclause, including AsciiDoc citations, into the current AsciiBib
442
442
  citation.
443
443
 
444
- The following is Metanorma Asciidoctor markup corresponding to the YAML
444
+ The following is Metanorma AsciiDoc markup corresponding to the YAML
445
445
  given above:
446
446
 
447
447
 
448
448
  [source,asciidoc]
449
- ....
449
+ ----
450
450
  [[ISO/TC211]]
451
451
  [%bibitem]
452
452
  === {blank}
@@ -547,7 +547,7 @@ organization::
547
547
  url::: www.iso.org
548
548
  abbreviation::: ISO
549
549
  subdivision::: division
550
- role::
550
+ role::
551
551
  type::: publisher
552
552
  description::: Publisher role
553
553
 
@@ -654,15 +654,15 @@ formattedref::
654
654
  content::: serieref
655
655
  language::: en
656
656
  script::: Latn
657
- ....
657
+ ----
658
658
 
659
659
  [[JSONPath]]
660
660
  == JSON Path style definition lists
661
661
 
662
662
  The foregoing structure requires frequent breakouts into open blocks, to deal
663
- with the limitation on Asciidoctor nested definition lists. An alternative is to
664
- represent the nested structure of Relaton records in a simple, one-level definition list,
665
- and to use the key for each key-value pair to represent the hierarchical nesting of entries,
663
+ with the limitation on AsciiDoc nested definition lists. An alternative is to
664
+ represent the nested structure of Relaton records in a simple, one-level definition list,
665
+ and to use the key for each key-value pair to represent the hierarchical nesting of entries,
666
666
  as a dot-delimited path of keys. For example,
667
667
 
668
668
  [source,asciidoc]
@@ -670,7 +670,7 @@ as a dot-delimited path of keys. For example,
670
670
  [%bibitem]
671
671
  === Rubber latex -- Sampling
672
672
  id:: iso123
673
- docid::
673
+ docid::
674
674
  type::: ISO
675
675
  id::: ISO 123
676
676
  ----
@@ -693,7 +693,7 @@ Whenever part of the key is repeated between entries, the entries are assumed to
693
693
  [%bibitem]
694
694
  === Rubber latex -- Sampling
695
695
  id:: iso123
696
- docid::
696
+ docid::
697
697
  type::: ISO
698
698
  id::: ISO 123
699
699
  docid::
@@ -754,11 +754,11 @@ contributor.person.contact.type:: phone
754
754
  contributor.person.contact.value:: 223322
755
755
  ----
756
756
 
757
- The following is Metanorma Asciidoctor markup corresponding to the YAML
757
+ The following is Metanorma AsciiDoc markup corresponding to the YAML
758
758
  given above, using JSON Path style definition lists instead of nested definition lists:
759
759
 
760
760
  [source,asciidoc]
761
- ....
761
+ ----
762
762
  [[ISO/TC211]]
763
763
  [%bibitem]
764
764
  === {blank}
@@ -1,20 +1,4 @@
1
1
  module RelatonBib
2
- # class SpecificLocalityType
3
- # SECTION = 'section'
4
- # CLAUSE = 'clause'
5
- # PART = 'part'
6
- # PARAGRAPH = 'paragraph'
7
- # CHAPTER = 'chapter'
8
- # PAGE = 'page'
9
- # WHOLE = 'whole'
10
- # TABLE = 'table'
11
- # ANNEX = 'annex'
12
- # FIGURE = 'figure'
13
- # NOTE = 'note'
14
- # EXAMPLE = 'example'
15
- # # generic String is allowed
16
- # end
17
-
18
2
  # Bibliographic item locality.
19
3
  class BibItemLocality
20
4
  # @return [String]
@@ -30,6 +14,13 @@ module RelatonBib
30
14
  # @param referenceFrom [String]
31
15
  # @param referenceTo [String, NilClass]
32
16
  def initialize(type, reference_from, reference_to = nil)
17
+ type_ptrn = %r{section|clause|part|paragraph|chapter|page|whole|table|
18
+ annex|figure|note|list|example|volume|issue|time|
19
+ locality:[a-zA-Z0-9_]+}x
20
+ unless type =~ type_ptrn
21
+ warn "[relaton-bib] WARNING: invalid locality type: #{type}"
22
+ end
23
+
33
24
  @type = type
34
25
  @reference_from = reference_from
35
26
  @reference_to = reference_to
@@ -49,4 +40,56 @@ module RelatonBib
49
40
  hash
50
41
  end
51
42
  end
43
+
44
+ class Locality < BibItemLocality
45
+ # @param builder [Nokogiri::XML::Builder]
46
+ def to_xml(builder)
47
+ builder.locality { |b| super(b) }
48
+ end
49
+ end
50
+
51
+ class LocalityStack
52
+ include RelatonBib
53
+
54
+ # @return [Array<RelatonBib::Locality>]
55
+ attr_reader :locality
56
+
57
+ # @param locality [Array<RelatonBib::Locality>]
58
+ def initialize(locality)
59
+ @locality = locality
60
+ end
61
+
62
+ # @param builder [Nokogiri::XML::Builder]
63
+ def to_xml(builder)
64
+ builder.localityStack do |b|
65
+ locality.each { |l| l.to_xml(b) }
66
+ end
67
+ end
68
+
69
+ # @returnt [Hash]
70
+ def to_hash
71
+ { "locality_stack" => single_element_array(locality) }
72
+ end
73
+ end
74
+
75
+ class SourceLocality < BibItemLocality
76
+ # @param builder [Nokogiri::XML::Builder]
77
+ def to_xml(builder)
78
+ builder.sourceLocality { |b| super(b) }
79
+ end
80
+ end
81
+
82
+ class SourceLocalityStack < LocalityStack
83
+ # @param builder [Nokogiri::XML::Builder]
84
+ def to_xml(builder)
85
+ builder.sourceLocalityStack do |b|
86
+ locality.each { |l| l.to_xml(b) }
87
+ end
88
+ end
89
+
90
+ # @returnt [Hash]
91
+ def to_hash
92
+ { "source_locality_stack" => single_element_array(locality) }
93
+ end
94
+ end
52
95
  end
@@ -167,8 +167,12 @@ module RelatonBib
167
167
  #
168
168
  # @param relation [Array<Hash>]
169
169
  # @option relation [String] :type
170
- # @option relation [RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem] :bibitem
171
- # @option relation [Array<RelatonBib::BibItemLocality>] :bib_locality
170
+ # @option relation [RelatonBib::BibliographicItem,
171
+ # RelatonIso::IsoBibliographicItem] :bibitem
172
+ # @option relation [Array<RelatonBib::Locality,
173
+ # RelatonBib::LocalityStack>] :locality
174
+ # @option relation [Array<RelatonBib::SourceLocality,
175
+ # RelatonBib::SourceLocalityStack>] :source_locality
172
176
  #
173
177
  # @param link [Array<Hash, RelatonBib::TypedUri>]
174
178
  # @option link [String] :type
@@ -25,17 +25,22 @@ module RelatonBib
25
25
  # @return [RelatonBib::BibliographicItem]
26
26
  attr_reader :bibitem
27
27
 
28
- # @return [Array<RelatonBib::BibItemLocality>]
29
- attr_reader :bib_locality
28
+ # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
29
+ attr_reader :locality
30
+
31
+ # @return [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>]
32
+ attr_reader :source_locality
30
33
 
31
34
  # @param type [String]
32
35
  # @param bibitem [RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem]
33
- # @param bib_locality [Array<RelatonBib::BibItemLocality>]
34
- def initialize(type:, bibitem:, bib_locality: [])
35
- type = "obsoletes" if type == "Now withdrawn"
36
- @type = type
37
- @bib_locality = bib_locality
38
- @bibitem = bibitem
36
+ # @param locality [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
37
+ # @param source_locality [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>]
38
+ def initialize(type:, bibitem:, locality: [], source_locality: [])
39
+ type = "obsoletes" if type == "Now withdrawn"
40
+ @type = type
41
+ @locality = locality
42
+ @source_locality = source_locality
43
+ @bibitem = bibitem
39
44
  end
40
45
 
41
46
  # @param builder [Nokogiri::XML::Builder]
@@ -44,16 +49,18 @@ module RelatonBib
44
49
  opts.delete :note
45
50
  builder.relation(type: type) do
46
51
  bibitem.to_xml(builder, **opts.merge(embedded: true))
47
- bib_locality.each do |l|
48
- builder.locality { l.to_xml builder }
49
- end
52
+ locality.each { |l| l.to_xml builder }
53
+ source_locality.each { |l| l.to_xml builder }
50
54
  end
51
55
  end
52
56
 
53
57
  # @return [Hash]
54
58
  def to_hash
55
59
  hash = { "type" => type, "bibitem" => bibitem.to_hash }
56
- hash["bib_locality"] = single_element_array(bib_locality) if bib_locality&.any?
60
+ hash["locality"] = single_element_array(locality) if locality&.any?
61
+ if source_locality&.any?
62
+ hash["source_locality"] = single_element_array(source_locality)
63
+ end
57
64
  hash
58
65
  end
59
66
  end
@@ -1,21 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
4
+
3
5
  module RelatonBib
4
6
  # Document relation collection
5
- class DocRelationCollection < Array
7
+ class DocRelationCollection
8
+ extend Forwardable
9
+
10
+ def_delegators :@array, :<<, :[], :first, :last, :empty?, :any?, :size,
11
+ :each, :detect, :map, :length
12
+
6
13
  # @param relation [Array<RelatonBib::DocumentRelation, Hash>]
7
14
  # @option relation [String] :type
8
15
  # @option relation [String] :identifier
9
16
  # @option relation [String, NIllClass] :url (nil)
10
- # @option relation [Array<RelatonBib::BibItemLocality>] :bib_locality
17
+ # @option relation [Array<RelatonBib::Locality,
18
+ # RelatonBib::LocalityStack>] :locality
19
+ # @option relation [Array<RelatonBib::SourceLocality,
20
+ # RelatonBib::SourceLocalityStack>] :source_locality
11
21
  # @option relation [RelatonBib::BibliographicItem, NillClass] :bibitem (nil)
12
22
  def initialize(relation)
13
- super relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(r) : r }
23
+ @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(r) : r }
14
24
  end
15
25
 
16
- # @return [Array<RelatonBib::DocumentRelation>]
26
+ # @return [RelatonBib::DocRelationCollection]
17
27
  def replaces
18
- select { |r| r.type == "replace" }
28
+ DocRelationCollection.new @array.select { |r| r.type == "replace" }
19
29
  end
20
30
  end
21
31
  end
@@ -252,40 +252,60 @@ module RelatonBib
252
252
  end
253
253
  end
254
254
 
255
+ # @param ret [Hash]
255
256
  def relations_hash_to_bib(ret)
256
257
  return unless ret[:relation]
257
258
 
258
259
  ret[:relation] = array(ret[:relation])
259
- ret[:relation]&.each_with_index do |r, i|
260
- relation_bibitem_hash_to_bib(ret, r, i)
261
- relation_biblocality_hash_to_bib(ret, r, i)
260
+ ret[:relation]&.each do |r|
261
+ relation_bibitem_hash_to_bib(r)
262
+ relation_locality_hash_to_bib(r)
263
+ relation_source_locality_hash_to_bib(r)
262
264
  end
263
265
  end
264
266
 
265
- # @param ret [Hash]
266
267
  # @param rel [Hash] relation
267
- # @param idx [Integr] index of relation
268
- def relation_bibitem_hash_to_bib(ret, rel, idx)
268
+ def relation_bibitem_hash_to_bib(rel)
269
269
  if rel[:bibitem]
270
- ret[:relation][idx][:bibitem] = bib_item(hash_to_bib(rel[:bibitem], true))
270
+ rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem], true)
271
271
  else
272
272
  warn "[relaton-bib] bibitem missing: #{rel}"
273
- ret[:relation][idx][:bibitem] = nil
273
+ rel[:bibitem] = nil
274
274
  end
275
275
  end
276
276
 
277
- # @param item [Hash]
278
- # @retirn [RelatonBib::BibliographicItem]
279
- def bib_item(item)
280
- BibliographicItem.new(item)
277
+ # @param item_hash [Hash]
278
+ # @return [RelatonBib::BibliographicItem]
279
+ def bib_item(item_hash)
280
+ BibliographicItem.new item_hash
281
281
  end
282
282
 
283
- def relation_biblocality_hash_to_bib(ret, rel, idx)
284
- ret[:relation][idx][:bib_locality] =
285
- array(rel[:bib_locality])&.map do |bl|
286
- BibItemLocality.new(bl[:type], bl[:reference_from],
287
- bl[:reference_to])
288
- end
283
+ # @param rel [Hash] relation
284
+ def relation_locality_hash_to_bib(rel)
285
+ rel[:locality] = array(rel[:locality])&.map do |bl|
286
+ ls = if bl[:locality_stack]
287
+ array(bl[:locality_stack]).map do |l|
288
+ Locality.new(l[:type], l[:reference_from], l[:reference_to])
289
+ end
290
+ else
291
+ [Locality.new(bl[:type], bl[:reference_from], bl[:reference_to])]
292
+ end
293
+ LocalityStack.new ls
294
+ end
295
+ end
296
+
297
+ # @param rel [Hash] relation
298
+ def relation_source_locality_hash_to_bib(rel)
299
+ rel[:source_locality] = array(rel[:source_locality])&.map do |sl|
300
+ sls = if sl[:source_locality_stack]
301
+ array(sl[:source_locality_stack]).map do |l|
302
+ SourceLocality.new(l[:type], l[:reference_from], l[:reference_to])
303
+ end
304
+ else
305
+ [SourceLocality.new(sl[:type], sl[:reference_from], sl[:reference_to])]
306
+ end
307
+ SourceLocalityStack.new sls
308
+ end
289
309
  end
290
310
 
291
311
  def series_hash_to_bib(ret)
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.9.2".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -8,9 +8,9 @@ module RelatonBib
8
8
  doc.remove_namespaces!
9
9
  bibitem = doc.at "/bibitem|/bibdata"
10
10
  if bibitem
11
- BibliographicItem.new(item_data(bibitem))
11
+ bib_item item_data(bibitem)
12
12
  else
13
- warn "[relato-bib] can't find bibitem or bibdata element in the XML"
13
+ warn "[relaton-bib] WARNING: can't find bibitem or bibdata element in the XML"
14
14
  end
15
15
  end
16
16
 
@@ -257,6 +257,8 @@ module RelatonBib
257
257
  end
258
258
  end
259
259
 
260
+ # @param item [Nokogiri::XML::Element]
261
+ # @return [Array<RelatonBib::ContributionInfo>]
260
262
  def fetch_contributors(item)
261
263
  item.xpath("./contributor").map do |c|
262
264
  entity = if (org = c.at "./organization") then get_org(org)
@@ -269,6 +271,8 @@ module RelatonBib
269
271
  end
270
272
  end
271
273
 
274
+ # @param item [Nokogiri::XML::Element]
275
+ # @return [Array<RelatonBib::FormattedString>]
272
276
  def fetch_abstract(item)
273
277
  item.xpath("./abstract").map do |a|
274
278
  FormattedString.new(
@@ -277,6 +281,8 @@ module RelatonBib
277
281
  end
278
282
  end
279
283
 
284
+ # @param item [Nokogiri::XML::Element]
285
+ # @return [RelatonBib::CopyrightAssociation]
280
286
  def fetch_copyright(item)
281
287
  cp = item.at("./copyright") || return
282
288
  org = cp&.at("owner/organization")
@@ -290,30 +296,71 @@ module RelatonBib
290
296
  CopyrightAssociation.new(owner: owner, from: from, to: to)
291
297
  end
292
298
 
299
+ # @param item [Nokogiri::XML::Element]
300
+ # @return [Arra<RelatonBib::TypedUri>]
293
301
  def fetch_link(item)
294
302
  item.xpath("./uri").map do |l|
295
303
  TypedUri.new type: l[:type], content: l.text
296
304
  end
297
305
  end
298
306
 
307
+ # @param item [Nokogiri::XML::Element]
308
+ # @return [Array<RelatonBib::DocumentRelation>]
299
309
  def fetch_relations(item)
300
310
  item.xpath("./relation").map do |rel|
301
- localities = rel.xpath("./locality").map do |l|
302
- ref_to = (rt = l.at("./referenceTo")) ? LocalizedString.new(rt.text) : nil
303
- BibItemLocality.new(
304
- l[:type],
305
- LocalizedString.new(l.at("./referenceFrom").text),
306
- ref_to,
307
- )
308
- end
309
311
  DocumentRelation.new(
310
312
  type: rel[:type]&.empty? ? nil : rel[:type],
311
- bibitem: BibliographicItem.new(item_data(rel.at("./bibitem"))),
312
- bib_locality: localities,
313
+ bibitem: bib_item(item_data(rel.at("./bibitem"))),
314
+ locality: localities(rel),
315
+ source_locality: source_localities(rel),
313
316
  )
314
317
  end
315
318
  end
316
319
 
320
+ # @param item_hash [Hash]
321
+ # @return [RelatonBib::BibliographicItem]
322
+ def bib_item(item_hash)
323
+ BibliographicItem.new item_hash
324
+ end
325
+
326
+ # @param rel [Nokogiri::XML::Element]
327
+ # @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
328
+ def localities(rel)
329
+ rel.xpath("./locality|./localityStack").map do |lc|
330
+ if lc[:type]
331
+ LocalityStack.new [locality(lc)]
332
+ else
333
+ LocalityStack.new lc.xpath("./locality").map { |l| locality l }
334
+ end
335
+ end
336
+ end
337
+
338
+ # @param loc [Nokogiri::XML::Element]
339
+ # @return [RelatonBib::Locality]
340
+ def locality(loc, klass = Locality)
341
+ ref_to = (rt = loc.at("./referenceTo")) ? LocalizedString.new(rt.text) : nil
342
+ klass.new(
343
+ loc[:type],
344
+ LocalizedString.new(loc.at("./referenceFrom").text),
345
+ ref_to,
346
+ )
347
+ end
348
+
349
+ # @param rel [Nokogiri::XML::Element]
350
+ # @return [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>]
351
+ def source_localities(rel)
352
+ rel.xpath("./sourceLocality|./sourceLocalityStack").map do |lc|
353
+ if lc[:type]
354
+ SourceLocalityStack.new [locality(lc, SourceLocality)]
355
+ else
356
+ sls = lc.xpath("./sourceLocality").map { |l| locality l, SourceLocality }
357
+ SourceLocalityStack.new sls
358
+ end
359
+ end
360
+ end
361
+
362
+ # @param item [Nokogiri::XML::Element]
363
+ # @return [RelatonBib::FormattedRef, NilClass]
317
364
  def fref(item)
318
365
  ident = item&.at("./formattedref")
319
366
  return unless ident
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2020-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -190,6 +190,7 @@ files:
190
190
  - ".github/workflows/windows.yml"
191
191
  - ".gitignore"
192
192
  - ".gitmodules"
193
+ - ".hound.yml"
193
194
  - ".rspec"
194
195
  - ".rubocop.yml"
195
196
  - Gemfile