relaton-bib 0.2.3 → 0.2.4

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
- SHA1:
3
- metadata.gz: 9d747bf888e86ace731f3530973d303018fc8a40
4
- data.tar.gz: e34fd357eb8de68e45b79347b3dca102c14a914a
2
+ SHA256:
3
+ metadata.gz: 79c5d34910126e13bbdea1f3a91e3071a269e6c369b5fca092568fe575fdddd6
4
+ data.tar.gz: f6320115abaa8b7e4e15aab3dfb846c5806e4811e5b412f0c12adb1113c909ba
5
5
  SHA512:
6
- metadata.gz: c0f9a37d0effe46c0df56db9c38ba8c5b5d5ae67f6d6de511cd85e47ca078ac8e9dc7c53e509421c7e501a343cc6fa13b11464e90b4b3e024e0ba29280053d7d
7
- data.tar.gz: 9a2d1682c08910a7c7abc6ee560f988004c38c42816677db7af1505f8ccc748353863861cb640ddb0836b655d6e2d5317dfc4266a9d831b480a72f35d1c27323
6
+ metadata.gz: 3f6d1623ece6d63cd329cdb12f7fd05d64b90bee9e6cced305d3bd767a6570e28e95b350cfec538dd1ac43ed82f2ba4ae9f93b92a5bbe5605b6efccb6333b1ff
7
+ data.tar.gz: b720da5c197a74cacf54e6f4b645223a186105a85a7b1fab5dd8c701007034c08081cd0f01b17723d3d968fd9592b34fcc80b37ef25c10d7cae872bd54e46b87
@@ -10,7 +10,7 @@ rvm:
10
10
  - 2.4
11
11
  - ruby-head
12
12
  before_install:
13
- - gem install bundler -v 2.0.1
13
+ - gem install bundler -v "~> 2"
14
14
  - bundle update
15
15
  matrix:
16
16
  allow_failures:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.2.3)
4
+ relaton-bib (0.2.4)
5
5
  addressable
6
6
  nokogiri (~> 1.8.4)
7
7
 
@@ -10,6 +10,7 @@ GEM
10
10
  specs:
11
11
  addressable (2.6.0)
12
12
  public_suffix (>= 2.0.2, < 4.0)
13
+ byebug (11.0.1)
13
14
  debase (0.2.2)
14
15
  debase-ruby_core_source (>= 0.10.2)
15
16
  debase-ruby_core_source (0.10.5)
@@ -21,7 +22,7 @@ GEM
21
22
  mini_portile2 (2.3.0)
22
23
  nokogiri (1.8.5)
23
24
  mini_portile2 (~> 2.3.0)
24
- public_suffix (3.1.0)
25
+ public_suffix (3.1.1)
25
26
  rake (10.5.0)
26
27
  rspec (3.8.0)
27
28
  rspec-core (~> 3.8.0)
@@ -49,6 +50,7 @@ PLATFORMS
49
50
 
50
51
  DEPENDENCIES
51
52
  bundler (~> 2.0)
53
+ byebug
52
54
  debase
53
55
  equivalent-xml (~> 0.6)
54
56
  rake (~> 10.0)
@@ -0,0 +1,36 @@
1
+ # Auto-generated !!! Do not edit it manually
2
+ # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
+ version: '{build}'
4
+
5
+ cache:
6
+ - vendor/bundle
7
+
8
+ environment:
9
+ matrix:
10
+ - RUBY_VERSION: 25
11
+ - RUBY_VERSION: 24
12
+ - RUBY_VERSION: _trunk
13
+
14
+ matrix:
15
+ allow_failures:
16
+ - RUBY_VERSION: _trunk
17
+
18
+ install:
19
+ - ps: . { iwr -useb https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/appveyor.ps1 } | iex
20
+ - refreshenv
21
+
22
+ build_script:
23
+ - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
24
+ - set GIT_TERMINAL_PROMPT=0
25
+ - gem install bundler -v "~> 2"
26
+ - bundle config --local path vendor/bundle
27
+ - bundle update
28
+ - bundle install
29
+
30
+ before_test:
31
+ - ruby -v
32
+ - gem -v
33
+ - bundle -v
34
+
35
+ test_script:
36
+ - bundle exec rake
@@ -0,0 +1,546 @@
1
+ = Relaton YAML
2
+
3
+ The following structure is in place for encoding bibitem as YAML objects, and is also used
4
+ to represent bibliographic entries in Metanorma Asciidoctor. The structure has not yet been
5
+ generalised to `bibdata/ext`, the flavour specific extensions of relaton.
6
+
7
+ Any elements which are arrays can also be populated by a hash or single element. For example,
8
+ the following are equivalent:
9
+
10
+ [source,yaml]
11
+ ....
12
+ titles:
13
+ - type: main
14
+ content: Geographic information
15
+ titles:
16
+ type: main
17
+ content: Geographic information
18
+ script:
19
+ - Latn
20
+ script: Latn
21
+ ....
22
+
23
+ In YAML, "on" is a reserved word, and thus cannot be used as a key. "value" is used as a synonym for
24
+ "on" in dates.
25
+
26
+ The structure below is given in YAML format:
27
+
28
+ [source,yaml]
29
+ ....
30
+ # bibliographic item anchor, used to crossreference within document
31
+ id: ISO/TC211
32
+ # date record was created
33
+ fetched: 2019-06-30
34
+ # titles are an array, with a mandatory type and content, and optional format, language and script
35
+ titles:
36
+ - type: main
37
+ content: Geographic information
38
+ - type: subtitle
39
+ content: Geographic information subtitle
40
+ language: en
41
+ script: Latn
42
+ format: text/plain
43
+ # type of document
44
+ type: standard
45
+ # document identifiers are an array, with a mandatory type and id component
46
+ docid:
47
+ type: ISO
48
+ id: TC211
49
+ # document number
50
+ docnumber: 211
51
+ # edition
52
+ edition: 1
53
+ # language is an array
54
+ language:
55
+ - en
56
+ - fr
57
+ # script is an array
58
+ script:
59
+ Latn
60
+ # version contains revision date and draft (as array)
61
+ version:
62
+ revision_date: 2019-04-01
63
+ draft: draft
64
+ # note is an array of type and content
65
+ biblionote:
66
+ type: bibnote
67
+ content: >
68
+ Mark set a major league
69
+ home run record in 1998.
70
+ # document status has stage, and optional substage and iteration
71
+ docstatus:
72
+ stage: stage
73
+ substage: substage
74
+ iteration: iteration
75
+ # date is an array, with mandatory type, and either an "on" value or a "from" and optional "to" value
76
+ dates:
77
+ - type: issued
78
+ value: 2014
79
+ - type: published
80
+ from: 2014-04
81
+ to: 2014-05
82
+ - type: accessed
83
+ value: 2015-05-20
84
+ # abstract is an array, with content, and optional language, script, format
85
+ abstract:
86
+ - content: >
87
+ ISO 19115-1:2014 defines the schema required for ...
88
+ - content: >
89
+ L'ISO 19115-1:2014 définit le schéma requis pour ...
90
+ language: fr
91
+ script: Latn
92
+ format: text/plain
93
+ # contributors are an array of entity/role pairs, where entity is either person or organization.
94
+ # The role is an array; if there is a more complete description, that is given as the second element
95
+ # of an array, and is itself an array.
96
+ # Organisations have attributes name, url, abbreviation, subdivision, contacts, identifiers
97
+ # Persons have attributes name, affiliation, contacts
98
+ # Person names have attributes surname, completename, initials, forename, additions, prefixes.
99
+ # Initials, forename, additions, prefixes are arrays.
100
+ # Name field values are either strings, or hashes, with content and language and script attributes.
101
+ # The language and script attribute can also be given on the name.
102
+ # Contacts are an array, containing either addresses, or other fields.
103
+ # Addresses are identified as hashes containing a city attribute; they can also contain a street
104
+ # (which is an array), a postcode, a state, and a country. The other contact fields
105
+ # are phones, emails, uris; they contain a type giving the field name, and a value.
106
+ # Affiliations are an array, and they contains an organization, and an optional description.
107
+ # The affiliation description can be a single string, or a hash of content, language, script, and format.
108
+ contributors:
109
+ - organization:
110
+ name: International Organization for Standardization
111
+ url: www.iso.org
112
+ abbreviation: ISO
113
+ subdivision: division
114
+ role:
115
+ - publisher
116
+ -
117
+ - Publisher role
118
+ - person:
119
+ name:
120
+ completename:
121
+ content: A. Bierman
122
+ language: en
123
+ affiliation:
124
+ - organization:
125
+ name: IETF
126
+ abbreviation: IETF
127
+ identifiers:
128
+ - type: uri
129
+ id: www.ietf.org
130
+ description: Affiliation description
131
+ contacts:
132
+ - street:
133
+ - 8 Street St
134
+ city: City
135
+ postcode: 123456
136
+ country: Country
137
+ state: State
138
+ - type: phone
139
+ value: 223322
140
+ role: author
141
+ - person:
142
+ name: IETF
143
+ abbreviation: IETF
144
+ identifiers:
145
+ - type: uri
146
+ id: www.ietf.org
147
+ role:
148
+ publisher
149
+ - person:
150
+ name:
151
+ language: en
152
+ initials:
153
+ - A.
154
+ surname: Bierman
155
+ affiliation:
156
+ - organization:
157
+ name: IETF
158
+ abbreviation: IETF
159
+ description:
160
+ content: Affiliation description
161
+ language: en
162
+ script: Latn
163
+ identifiers:
164
+ - type: uri
165
+ id: www.person.com
166
+ roles:
167
+ author
168
+ # copyright consists of an owner (a hash containing the fields of an organisation),
169
+ # a "from" date, and an optional "to" date
170
+ copyright:
171
+ owner:
172
+ name: International Organization for Standardization
173
+ abbreviation: ISO
174
+ url: www.iso.org
175
+ from: 2014
176
+ to: 2020
177
+ # link is an array of URIs, with a type and content
178
+ link:
179
+ - type: src
180
+ content: https://www.iso.org/standard/53798.html
181
+ - type: obp
182
+ content: https://www.iso.org/obp/ui/#!iso:std:53798:en
183
+ - type: rss
184
+ content: https://www.iso.org/contents/data/standard/05/37/53798.detail.rss
185
+ # relations are an array of type, bibitem, and bib_locality.
186
+ # bibitem contains any of the attributes of a bibliographic item.
187
+ # bib_locality is an array that contains a type, a reference_from, and optionally a reference_to
188
+ relations:
189
+ - type: updates
190
+ bibitem:
191
+ formattedref: ISO 19115:2003
192
+ bib_locality:
193
+ type: page
194
+ reference_from: 7
195
+ reference_to: 10
196
+ - type: updates
197
+ bibitem:
198
+ type: standard
199
+ formattedref: ISO 19115:2003/Cor 1:2006
200
+ # series are an array, containing a type, and either a formattedref, or:
201
+ # a title, a place, an organization (string),
202
+ # an abbreviation, a from, a to, a number, and a partnumber.
203
+ # The series title, like the titles of bibliographic items, contains a type,
204
+ # content, and optional language, script, and format attributes.
205
+ # The abbreviation and formattedref are either a string,
206
+ # or a hash containing content, language, and script.
207
+ series:
208
+ - type: main
209
+ title:
210
+ type: original
211
+ content: ISO/IEC FDIS 10118-3
212
+ language: en
213
+ script: Latn
214
+ format: text/plain
215
+ place: Serie's place
216
+ organization: Serie's organization
217
+ abbreviation:
218
+ content: ABVR
219
+ language: en
220
+ script: Latn
221
+ from: 2009-02-01
222
+ to: 2010-12-20
223
+ number: serie1234
224
+ partnumber: part5678
225
+ - type: alt
226
+ formattedref:
227
+ content: serieref
228
+ language: en
229
+ script: Latn
230
+ # medium contains a form, a size, and a scale
231
+ medium:
232
+ form: medium form
233
+ size: medium size
234
+ scale: medium scale
235
+ # place is an array of strings
236
+ place: bib place
237
+ # extent is an array, containing type, a reference_from, and an optional reference_to
238
+ extent:
239
+ type: section
240
+ reference_from: 7
241
+ # accesslocation is an array of strings
242
+ accesslocation:
243
+ - accesslocation1
244
+ - accesslocation2
245
+ # classification is an array of type and value
246
+ classification:
247
+ type: type
248
+ value: value
249
+ # validity contains a begins date, an ends date, and a revision date
250
+ validity:
251
+ begins: 2010-10-10 12:21
252
+ ends: 2011-02-03 18:30
253
+ revision: 2011-03-04 09:00
254
+ ....
255
+
256
+ The Metanorma Asciidoctor representation of this hash structure
257
+ in a bibliography
258
+ is as a definition list, with nested definition lists for nested structures.
259
+ Repeating elements in a hash can be realised as ordered or unordered lists.
260
+ However, given how awkward lists of definition lists are in Asciidoctor,
261
+ Metanorma Asciidoctor also supports representing repeating elements
262
+ by repeating the key for that entry.
263
+
264
+ Each Relaton entry in a bibliography is represented in Metanorma Asciidoctor
265
+ through a subclause with option attribute `[%bibitem]`. Any title given to the
266
+ subclause is treated as the title for the bibliographic entry, with language `en`,
267
+ script `Latn`, format `text/plain`, and type `main`. If there is no such title
268
+ for the entry, the subclause title should be left as `{blank}`.
269
+
270
+ So the following is a very simple reference in Metanorma Asciidoctor:
271
+
272
+ [source,asciidoctor]
273
+ ----
274
+ [%bibitem]
275
+ === Rubber latex -- Sampling
276
+ id:: iso123
277
+ docid::
278
+ type::: ISO
279
+ id::: ISO 123
280
+ docid::
281
+ type::: ABC
282
+ id::: 32784
283
+ type:: standard
284
+ ----
285
+
286
+ The anchor crossreference for the bibliographic entry may be encoded as the
287
+ `id` entry in the definition list, or as the normal Asciidoctor anchor on the
288
+ subclause, which takes priority over it:
289
+
290
+ [source,asciidoctor]
291
+ ----
292
+ [[iso123]]
293
+ [%bibitem]
294
+ === Rubber latex -- Sampling
295
+ docid::
296
+ type::: ISO
297
+ id::: ISO 123
298
+ type:: standard
299
+ ----
300
+
301
+ Asciidoctor does not currently cope with definition lists more than four levels
302
+ deep. If deeper nesting is needed, you will need to attach a new definition
303
+ list with a list continuation:
304
+
305
+ [source,asciidoctor]
306
+ ----
307
+ [[iso123]]
308
+ [%bibitem]
309
+ === Rubber latex -- Sampling
310
+ docid::
311
+ type::: ISO
312
+ id::: ISO 123
313
+ type:: standard
314
+ contributors::
315
+ roles::: author
316
+ person:::
317
+ name::::
318
+ +
319
+ --
320
+ completename::
321
+ language::: en
322
+ content::: Fred
323
+ --
324
+ ----
325
+
326
+ The most heavily nested parts of a Relaton entry are the contributors,
327
+ series, and relations. To prevent excessive depth of nesting for such
328
+ entries, they can be marked up as subclauses within the entry, with the clause
329
+ titles "contributor", "series", and "relation". Each subclause contains
330
+ a new definition list, with its definition list reset to zero depth;
331
+ the subclauses can be repeated for multiple instances of the same subentity.
332
+
333
+ The following is Metanorma Asciidoctor markup corresponding to the YAML
334
+ given above:
335
+
336
+
337
+ [source,asciidoc]
338
+ ....
339
+ [[ISO/TC211]]
340
+ [%bibitem]
341
+ === {blank}
342
+ fetched:: 2019-06-30
343
+ title::
344
+ type::: main
345
+ content::: Geographic information
346
+ title::
347
+ type::: subtitle
348
+ content::: Geographic information subtitle
349
+ language::: en
350
+ script::: Latn
351
+ format::: text/plain
352
+ type:: standard
353
+ docid::
354
+ type::: ISO
355
+ id::: TC211
356
+ docnumber:: 211
357
+ edition:: 1
358
+ language::
359
+ * en
360
+ * fr
361
+ script:: Latn
362
+ version::
363
+ revision_date::: 2019-04-01
364
+ draft::: draft
365
+ biblionote::
366
+ type::: bibnote
367
+ content:::
368
+ +
369
+ ---
370
+ Mark set a major league
371
+ home run record in 1998.
372
+ ---
373
+ docstatus::
374
+ stage::: stage
375
+ substage::: substage
376
+ iteration::: iteration
377
+ dates::
378
+ type::: issued
379
+ value::: 2014
380
+ dates::
381
+ type::: published
382
+ from::: 2014-04
383
+ to::: 2014-05
384
+ dates::
385
+ type::: accessed
386
+ value::: 2015-05-20
387
+ abstract::
388
+ content:::
389
+ +
390
+ ---
391
+ ISO 19115-1:2014 defines the schema required for ...
392
+ ---
393
+ abstract::
394
+ content::: L'ISO 19115-1:2014 définit le schéma requis pour ...
395
+ language::: fr
396
+ script::: Latn
397
+ format::: text/plain
398
+ copyright::
399
+ owner:::
400
+ name:::: International Organization for Standardization
401
+ abbreviation:::: ISO
402
+ url:::: www.iso.org
403
+ from::: 2014
404
+ to::: 2020
405
+ link::
406
+ type::: src
407
+ content::: https://www.iso.org/standard/53798.html
408
+ link::
409
+ type::: obp
410
+ content::: https://www.iso.org/obp/ui/#!iso:std:53798:en
411
+ link::
412
+ type::: rss
413
+ content::: https://www.iso.org/contents/data/standard/05/37/53798.detail.rss
414
+ medium::
415
+ form::: medium form
416
+ size::: medium size
417
+ scale::: medium scale
418
+ place:: bib place
419
+ extent::
420
+ type::: section
421
+ reference_from::: 7
422
+ accesslocation::
423
+ * accesslocation1
424
+ * accesslocation2
425
+ classification::
426
+ type::: type
427
+ value::: value
428
+ validity::
429
+ begins::: 2010-10-10 12:21
430
+ ends::: 2011-02-03 18:30
431
+
432
+
433
+ ==== Contributor
434
+ person::
435
+ name::: International Organization for Standardization
436
+ url::: www.iso.org
437
+ abbreviation::: ISO
438
+ subdivision::: division
439
+ role::
440
+ * publisher
441
+ *
442
+ ** Publisher role
443
+
444
+ ==== Contributor
445
+ person::
446
+ name:::
447
+ completename::::
448
+ content::::: A. Bierman
449
+ language::::: en
450
+ affiliation:::
451
+ organization::::
452
+ name::::: IETF
453
+ abbreviation::::: IETF
454
+ identifiers:::::
455
+ +
456
+ ---
457
+ type:: uri
458
+ id:: www.ietf.org
459
+ ---
460
+ description:::: Affiliation description
461
+ contacts:::
462
+ street::::
463
+ * 8 Street St
464
+ city:::: City
465
+ postcode:::: 123456
466
+ country:::: Country
467
+ state:::: State
468
+ contacts:::
469
+ type:::: phone
470
+ value:::: 223322
471
+ role:: author
472
+
473
+ ==== Contributor
474
+ person::
475
+ name::: IETF
476
+ abbreviation::: IETF
477
+ identifiers:::
478
+ type:::: uri
479
+ id:::: www.ietf.org
480
+ role:: publisher
481
+
482
+ ==== Contributor
483
+ person::
484
+ name:::
485
+ language:::: en
486
+ initials:::: A.
487
+ surname:::: Bierman
488
+ affiliation:::
489
+ organization::::
490
+ name::::: IETF
491
+ abbreviation::::: IETF
492
+ description::::
493
+ content::::: Affiliation description
494
+ language::::: en
495
+ script::::: Latn
496
+ identifiers:::
497
+ type:::: uri
498
+ id:::: www.person.com
499
+ roles:: author
500
+
501
+ ==== Relation
502
+ type:: updates
503
+ bibitem::
504
+ formattedref::: ISO 19115:2003
505
+ bib_locality:::
506
+ type:::: page
507
+ reference_from:::: 7
508
+ reference_to:::: 10
509
+
510
+ ==== Relation
511
+ type::: updates
512
+ bibitem:::
513
+ type::: standard
514
+ formattedref::: ISO 19115:2003/Cor 1:2006
515
+
516
+ ==== Series
517
+ type:: main
518
+ title::
519
+ type::: original
520
+ content::: ISO/IEC FDIS 10118-3
521
+ language::: en
522
+ script::: Latn
523
+ format::: text/plain
524
+ place:: Serie's place
525
+ organization:: Serie's organization
526
+ abbreviation::
527
+ content::: ABVR
528
+ language::: en
529
+ script::: Latn
530
+ from:: 2009-02-01
531
+ to:: 2010-12-20
532
+ number:: serie1234
533
+ partnumber:: part5678
534
+
535
+ ==== Series
536
+ type:: alt
537
+ formattedref::
538
+ content::: serieref
539
+ language::: en
540
+ script::: Latn
541
+ ....
542
+
543
+
544
+
545
+
546
+
@@ -1,4 +1,17 @@
1
1
  module RelatonBib
2
+ class << self
3
+ def biblionote_hash_to_bib(ret)
4
+ return unless ret[:biblionote]
5
+ ret[:biblionote] = array(ret[:biblionote])
6
+ (ret[:biblionote])&.each_with_index do |n, i|
7
+ ret[:biblionote][i] =
8
+ BiblioNote.new(content: n[:content], type: n[:type],
9
+ language: n[:language],
10
+ script: n[:script], format: n[:format])
11
+ end
12
+ end
13
+ end
14
+
2
15
  class BiblioNote < FormattedString
3
16
  # @return [String]
4
17
  attr_reader :type
@@ -0,0 +1,36 @@
1
+ module RelatonBib
2
+ # Version
3
+ class << self
4
+ def version_hash_to_bib(ret)
5
+ return unless ret[:version]
6
+ ret[:version][:draft] = array(ret[:version][:draft])
7
+ ret[:version] and ret[:version] = BibliographicItem::Version.new(
8
+ ret[:version][:revision_date], ret[:version][:draft])
9
+ end
10
+ end
11
+
12
+ class BibliographicItem
13
+ class Version
14
+ # @return [String]
15
+ attr_reader :revision_date
16
+
17
+ # @return [Array<String>]
18
+ attr_reader :draft
19
+
20
+ # @param revision_date [String]
21
+ # @param draft [Array<String>]
22
+ def initialize(revision_date = nil, draft = [])
23
+ @revision_date = revision_date
24
+ @draft = draft
25
+ end
26
+
27
+ # @param builder [Nokogiri::XML::Builder]
28
+ def to_xml(builder)
29
+ builder.version do
30
+ builder.revision_date revision_date if revision_date
31
+ draft.each { |d| builder.draft d }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -3,10 +3,25 @@
3
3
  require "time"
4
4
 
5
5
  module RelatonBib
6
+ class << self
7
+ def dates_hash_to_bib(ret)
8
+ return unless ret[:dates]
9
+ ret[:dates] = array(ret[:dates])
10
+ ret[:dates].each_with_index do |d, i|
11
+ # value is synonym of on: it is reserved word in YAML
12
+ if d[:value]
13
+ ret[:dates][i][:on] ||= d[:value]
14
+ ret[:dates][i].delete(:value)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
6
20
  # Bibliographic date.
7
21
  class BibliographicDate
8
22
  TYPES = %w[published accessed created implemented obsoleted confirmed
9
- updated issued transmitted copied unchanged circulated].freeze
23
+ updated issued transmitted copied unchanged circulated
24
+ ].freeze
10
25
 
11
26
  # @return [String]
12
27
  attr_reader :type
@@ -26,7 +41,8 @@ module RelatonBib
26
41
  def initialize(type:, on: nil, from: nil, to: nil)
27
42
  raise ArgumentError, "expected :on or :from argument" unless on || from
28
43
 
29
- raise ArgumentError, %{Type "#{type}" is ivalid.} unless TYPES.include?(type)
44
+ TYPES.include?(type) or
45
+ raise ArgumentError, %{Type "#{type}" is invalid.} unless
30
46
 
31
47
  @type = type
32
48
  @on = parse_date on
@@ -19,39 +19,68 @@ require "relaton_bib/document_relation"
19
19
  require "relaton_bib/bib_item_locality"
20
20
  require "relaton_bib/xml_parser"
21
21
  require "relaton_bib/biblio_note"
22
+ require "relaton_bib/biblio_version"
22
23
  require "relaton_bib/workers_pool"
23
-
24
+ require "relaton_bib/hash_to_bib.rb"
24
25
 
25
26
  module RelatonBib
26
- # Bibliographic item
27
- class BibliographicItem
28
- class Version
29
- # @return [String]
30
- attr_reader :revision_date
31
-
32
- # @return [Array<String>]
33
- attr_reader :draft
34
-
35
- # @oaram revision_date [String]
36
- # @param draft [Array<String>]
37
- def initialize(revision_date = nil, draft = [])
38
- @revision_date = revision_date
39
- @draft = draft
27
+ class << self
28
+ def extent_hash_to_bib(ret)
29
+ return unless ret[:extent]
30
+ ret[:extent] = array(ret[:extent])
31
+ ret[:extent]&.each_with_index do |e, i|
32
+ ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
33
+ e[:reference_to])
40
34
  end
35
+ end
41
36
 
42
- # @param builder [Nokogiri::XML::Builder]
43
- def to_xml(builder)
44
- builder.version do
45
- builder.revision_date revision_date if revision_date
46
- draft.each { |d| builder.draft d }
47
- end
37
+ def title_hash_to_bib(ret)
38
+ return unless ret[:titles]
39
+ ret[:titles] = array(ret[:titles])
40
+ ret[:titles] = ret[:titles].map do |t|
41
+ t.is_a?(Hash) ? t : { content: t, language: "en", script: "Latn",
42
+ format: "text/plain", type: "main" }
48
43
  end
49
44
  end
50
45
 
46
+ def language_hash_to_bib(ret)
47
+ return unless ret[:language]
48
+ ret[:language] = array(ret[:language])
49
+ end
50
+
51
+ def script_hash_to_bib(ret)
52
+ return unless ret[:script]
53
+ ret[:script] = array(ret[:script])
54
+ end
55
+
56
+ def abstract_hash_to_bib(ret)
57
+ return unless ret[:abstract]
58
+ ret[:abstract] = array(ret[:abstract])
59
+ end
60
+
61
+ def link_hash_to_bib(ret)
62
+ return unless ret[:link]
63
+ ret[:link] = array(ret[:link])
64
+ end
65
+
66
+ def place_hash_to_bib(ret)
67
+ return unless ret[:place]
68
+ ret[:place] = array(ret[:place])
69
+ end
70
+
71
+ def accesslocation_hash_to_bib(ret)
72
+ return unless ret[:accesslocation]
73
+ ret[:accesslocation] = array(ret[:accesslocation])
74
+ end
75
+ end
76
+
77
+ # Bibliographic item
78
+ class BibliographicItem
51
79
  TYPES = %W[article book booklet conference manual proceedings presentation
52
80
  thesis techreport standard unpublished map electronic\sresource
53
81
  audiovisual film video broadcast graphic_work music patent
54
- inbook incollection inproceedings journal].freeze
82
+ inbook incollection inproceedings journal
83
+ ].freeze
55
84
 
56
85
  # @return [String]
57
86
  attr_reader :id
@@ -1,4 +1,15 @@
1
1
  module RelatonBib
2
+ class << self
3
+ def classification_hash_to_bib(ret)
4
+ #ret[:classification] = [ret[:classification]] unless ret[:classification].is_a?(Array)
5
+ #ret[:classification]&.each_with_index do |c, i|
6
+ #ret[:classification][i] = RelatonBib::Classification.new(c)
7
+ #end
8
+ ret[:classification] and
9
+ ret[:classification] = Classification.new(ret[:classification])
10
+ end
11
+ end
12
+
2
13
  class Classification
3
14
  # @return [String, NilClass]
4
15
  attr_reader :type
@@ -19,4 +30,4 @@ module RelatonBib
19
30
  xml[:type] = type if type
20
31
  end
21
32
  end
22
- end
33
+ end
@@ -4,10 +4,25 @@ require "relaton_bib/person"
4
4
 
5
5
  # RelatonBib module
6
6
  module RelatonBib
7
+ class << self
8
+ def contributors_hash_to_bib(ret)
9
+ return unless ret[:contributors]
10
+ ret[:contributors] = array(ret[:contributors])
11
+ ret[:contributors]&.each_with_index do |c, i|
12
+ ret[:contributors][i][:roles] = array(ret[:contributors][i][:roles])
13
+ ret[:contributors][i][:entity] = c[:person] ?
14
+ person_hash_to_bib(c[:person]) : org_hash_to_bib(c[:organization])
15
+ ret[:contributors][i].delete(:person)
16
+ ret[:contributors][i].delete(:organization)
17
+ end
18
+ end
19
+ end
20
+
7
21
  # Contributor's role.
8
22
  class ContributorRole
9
23
  TYPES = %w[author performer publisher editor adapter translator
10
- distributor].freeze
24
+ distributor
25
+ ].freeze
11
26
 
12
27
  # @return [Array<RelatonBib::FormattedString>]
13
28
  attr_reader :description
@@ -3,6 +3,32 @@
3
3
  require "uri"
4
4
 
5
5
  module RelatonBib
6
+ class << self
7
+ def affiliation_hash_to_bib(c)
8
+ return [] unless c[:affiliation]
9
+ array(c[:affiliation]).map do |a|
10
+ a[:description] = array(a[:description])&.map do |d|
11
+ FormattedString.new(d.nil? ? { content: nil } :
12
+ { content: d[:content], language: d[:language],
13
+ script: d[:language], format: d[:format] })
14
+ end
15
+ Affilation.new(
16
+ Organization.new(org_hash_to_bib(a[:organization])), a[:description])
17
+ end
18
+ end
19
+
20
+ def contacts_hash_to_bib(c)
21
+ return [] unless c[:contacts]
22
+ array(c[:contacts]).map do |a|
23
+ (a[:city] || a[:country]) ?
24
+ RelatonBib::Address.new(
25
+ street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
26
+ country: a[:country], state: a[:state]) :
27
+ RelatonBib::Contact.new(type: a[:type], value: a[:value])
28
+ end
29
+ end
30
+ end
31
+
6
32
  # Address class.
7
33
  class Address
8
34
  # @return [Array<String>]
@@ -1,5 +1,16 @@
1
1
  module RelatonBib
2
2
  # Document identifier.
3
+
4
+ class << self
5
+ def docid_hash_to_bib(ret)
6
+ return unless ret[:docid]
7
+ ret[:docid] = array(ret[:docid])
8
+ ret[:docid]&.each_with_index do |id, i|
9
+ ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: id[:type])
10
+ end
11
+ end
12
+ end
13
+
3
14
  class DocumentIdentifier
4
15
  # @return [String]
5
16
  attr_reader :id
@@ -11,6 +11,33 @@ module RelatonBib
11
11
  # IDENTICAL = 'identical'
12
12
  # NONEQUIVALENT = 'nonequivalent'
13
13
  # end
14
+ class << self
15
+ def relations_hash_to_bib(ret)
16
+ return unless ret[:relations]
17
+ ret[:relations] = array(ret[:relations])
18
+ ret[:relations]&.each_with_index do |r, i|
19
+ relation_bibitem_hash_to_bib(ret, r, i)
20
+ relation_biblocality_hash_to_bib(ret, r, i)
21
+ end
22
+ end
23
+
24
+ def relation_bibitem_hash_to_bib(ret, r, i)
25
+ if r[:bibitem] then ret[:relations][i][:bibitem] =
26
+ BibliographicItem.new(hash_to_bib(r[:bibitem], true))
27
+ else
28
+ warn "bibitem missing: #{r}"
29
+ ret[:relations][i][:bibitem] = nil
30
+ end
31
+ end
32
+
33
+ def relation_biblocality_hash_to_bib(ret, r, i)
34
+ ret[:relations][i][:bib_locality] =
35
+ array(r[:bib_locality])&.map do |bl|
36
+ BibItemLocality.new(bl[:type], bl[:reference_from],
37
+ bl[:reference_to])
38
+ end
39
+ end
40
+ end
14
41
 
15
42
  # Documett relation
16
43
  class DocumentRelation
@@ -3,7 +3,16 @@
3
3
  require "relaton_bib/localized_string"
4
4
 
5
5
  module RelatonBib
6
- # Dovument status.
6
+ class << self
7
+ def docstatus_hash_to_bib(ret)
8
+ ret[:docstatus] and ret[:docstatus] =
9
+ DocumentStatus.new(stage: ret[:docstatus][:stage],
10
+ substage: ret[:docstatus][:substage],
11
+ iteration: ret[:docstatus][:iteration])
12
+ end
13
+ end
14
+
15
+ # Document status.
7
16
  class DocumentStatus
8
17
  # @return [String]
9
18
  attr_reader :stage
@@ -1,6 +1,13 @@
1
1
  require "relaton_bib/formatted_string"
2
2
 
3
3
  module RelatonBib
4
+ class << self
5
+ def formattedref_hash_to_bib(ret)
6
+ ret[:formattedref] and ret[:formattedref] =
7
+ formattedref(ret[:formattedref])
8
+ end
9
+ end
10
+
4
11
  class FormattedRef < FormattedString
5
12
  # @param [Nokogiri::XML::Builder]
6
13
  def to_xml(builder)
@@ -0,0 +1,70 @@
1
+ module RelatonBib
2
+ class << self
3
+ def hash_to_bib(args, nested = false)
4
+ return nil unless args.is_a?(Hash)
5
+ ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
6
+ timestamp_hash(ret) unless nested
7
+ title_hash_to_bib(ret)
8
+ link_hash_to_bib(ret)
9
+ language_hash_to_bib(ret)
10
+ script_hash_to_bib(ret)
11
+ dates_hash_to_bib(ret)
12
+ docid_hash_to_bib(ret)
13
+ version_hash_to_bib(ret)
14
+ biblionote_hash_to_bib(ret)
15
+ abstract_hash_to_bib(ret)
16
+ formattedref_hash_to_bib(ret)
17
+ docstatus_hash_to_bib(ret)
18
+ contributors_hash_to_bib(ret)
19
+ relations_hash_to_bib(ret)
20
+ series_hash_to_bib(ret)
21
+ medium_hash_to_bib(ret)
22
+ place_hash_to_bib(ret)
23
+ extent_hash_to_bib(ret)
24
+ accesslocation_hash_to_bib(ret)
25
+ classification_hash_to_bib(ret)
26
+ validity_hash_to_bib(ret)
27
+ ret
28
+ end
29
+
30
+ def timestamp_hash(ret)
31
+ ret[:fetched] ||= Date.today.to_s
32
+ end
33
+
34
+ def symbolize(obj)
35
+ obj.is_a? Hash and
36
+ return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo}
37
+ obj.is_a? Array and
38
+ return obj.inject([]){|memo,v | memo << symbolize(v); memo}
39
+ return obj
40
+ end
41
+
42
+ def array(a)
43
+ return [] unless a
44
+ return [a] unless a.is_a?(Array)
45
+ a
46
+ end
47
+
48
+ def localname(f, c)
49
+ return nil if f.nil?
50
+ f.is_a?(Hash) and lang = f[:language]
51
+ lang ||= c[:name][:language]
52
+ f.is_a?(Hash) and script = f[:script]
53
+ script ||= c[:name][:script]
54
+ f.is_a?(Hash) ?
55
+ RelatonBib::LocalizedString.new(f[:content], lang, script) :
56
+ RelatonBib::LocalizedString.new(f, lang, script)
57
+ end
58
+
59
+ def localizedstring(f)
60
+ f.is_a?(Hash) ?
61
+ RelatonBib::LocalizedString.new(f[:content], f[:language], f[:script]) :
62
+ RelatonBib::LocalizedString.new(f)
63
+ end
64
+
65
+ def formattedref(f)
66
+ f.is_a?(Hash) ? RelatonBib::FormattedRef.new(f) :
67
+ RelatonBib::FormattedRef.new(content: f)
68
+ end
69
+ end
70
+ end
@@ -1,4 +1,10 @@
1
1
  module RelatonBib
2
+ class << self
3
+ def medium_hash_to_bib(ret)
4
+ ret[:medium] and ret[:medium] = Medium.new(ret[:medium])
5
+ end
6
+ end
7
+
2
8
  class Medium
3
9
  # @return [String, NilClass]
4
10
  attr_reader :form, :size, :scale
@@ -21,4 +27,4 @@ module RelatonBib
21
27
  end
22
28
  end
23
29
  end
24
- end
30
+ end
@@ -3,6 +3,16 @@
3
3
  require "relaton_bib/contributor"
4
4
 
5
5
  module RelatonBib
6
+ class << self
7
+ def org_hash_to_bib(c)
8
+ return nil if c.nil?
9
+ c[:identifiers] = array(c[:identifiers])&.map do |a|
10
+ OrgIdentifier.new(a[:type], a[:id])
11
+ end
12
+ c
13
+ end
14
+ end
15
+
6
16
  # module OrgIdentifierType
7
17
  # ORCID = 'orcid'
8
18
  # URI = 'uri'
@@ -51,7 +61,9 @@ module RelatonBib
51
61
  attr_reader :identifiers
52
62
 
53
63
  def hash2locstr(name)
54
- name.is_a?(Hash) ? LocalizedString.new(name[:content], name[:language], name[:script]) : LocalizedString.new(name)
64
+ name.is_a?(Hash) ?
65
+ LocalizedString.new(name[:content], name[:language], name[:script]) :
66
+ LocalizedString.new(name)
55
67
  end
56
68
 
57
69
  # @param name [String, Hash, Array<String, Hash>]
@@ -3,6 +3,35 @@
3
3
  require "relaton_bib/contributor"
4
4
 
5
5
  module RelatonBib
6
+ class << self
7
+ def person_hash_to_bib(c)
8
+ Person.new(
9
+ name: fullname_hash_to_bib(c),
10
+ affiliation: affiliation_hash_to_bib(c),
11
+ contacts: contacts_hash_to_bib(c),
12
+ identifiers: person_identifiers_hash_to_bib(c),
13
+ )
14
+ end
15
+
16
+ def fullname_hash_to_bib(c)
17
+ n = c[:name]
18
+ FullName.new(
19
+ forenames: array(n[:forenames])&.map { |f| localname(f, c) },
20
+ initials: array(n[:initials])&.map { |f| localname(f, c) },
21
+ additions: array(n[:additions])&.map { |f| localname(f, c) },
22
+ prefix: array(n[:prefix])&.map { |f| localname(f, c) },
23
+ surname: localname(n[:surname], c),
24
+ completename: localname(n[:completename], c),
25
+ )
26
+ end
27
+
28
+ def person_identifiers_hash_to_bib(c)
29
+ array(c[:identifiers])&.map do |a|
30
+ PersonIdentifier.new(a[:type], a[:id])
31
+ end
32
+ end
33
+ end
34
+
6
35
  # Person's full name
7
36
  class FullName
8
37
  # @return [Array<RelatonBib::LocalizedString>]
@@ -1,6 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonBib
4
+ class << self
5
+ def series_hash_to_bib(ret)
6
+ array(ret[:series])&.each_with_index do |s, i|
7
+ s[:formattedref] and s[:formattedref] = formattedref(s[:formattedref])
8
+ if s[:title]
9
+ s[:title] = { content: s[:title] } unless s.is_a?(Hash)
10
+ s[:title] = TypedTitleString.new(s[:title])
11
+ end
12
+ s[:abbreviation] and
13
+ s[:abbreviation] = localizedstring(s[:abbreviation])
14
+ ret[:series][i] = Series.new(s)
15
+ end
16
+ end
17
+ end
18
+
4
19
  #
5
20
  # Series class.
6
21
  #
@@ -29,7 +29,9 @@ module RelatonBib
29
29
  if args[:title]
30
30
  @title = args[:title]
31
31
  else
32
- fsargs = args.select { |k, _v| %i[content language script format].include? k }
32
+ fsargs = args.select do |k, _v|
33
+ %i[content language script format].include? k
34
+ end
33
35
  @title = FormattedString.new(fsargs)
34
36
  end
35
37
  end
@@ -1,4 +1,14 @@
1
1
  module RelatonBib
2
+ class << self
3
+ def validity_hash_to_bib(ret)
4
+ return unless ret[:validity]
5
+ ret[:validity][:begins] and b = Time.parse(ret[:validity][:begins])
6
+ ret[:validity][:ends] and e = Time.parse(ret[:validity][:ends])
7
+ ret[:validity][:revision] and r = Time.parse(ret[:validity][:revision])
8
+ ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
9
+ end
10
+ end
11
+
2
12
  class Validity
3
13
  # @return [Time, NilClass]
4
14
  attr_reader :begins
@@ -28,4 +38,4 @@ module RelatonBib
28
38
  end
29
39
  end
30
40
  end
31
- end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
  spec.add_development_dependency "ruby-debug-ide"
32
32
  spec.add_development_dependency "simplecov"
33
+ spec.add_development_dependency "byebug"
33
34
 
34
35
  spec.add_dependency "addressable"
35
36
  spec.add_dependency "nokogiri", "~> 1.8.4"
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-26 00:00:00.000000000 Z
11
+ date: 2019-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: addressable
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -152,11 +166,14 @@ files:
152
166
  - LICENSE.txt
153
167
  - README.adoc
154
168
  - Rakefile
169
+ - appveyor.yml
155
170
  - bin/console
156
171
  - bin/setup
172
+ - docs/hash.adoc
157
173
  - lib/relaton_bib.rb
158
174
  - lib/relaton_bib/bib_item_locality.rb
159
175
  - lib/relaton_bib/biblio_note.rb
176
+ - lib/relaton_bib/biblio_version.rb
160
177
  - lib/relaton_bib/bibliographic_date.rb
161
178
  - lib/relaton_bib/bibliographic_item.rb
162
179
  - lib/relaton_bib/classification.rb
@@ -169,6 +186,7 @@ files:
169
186
  - lib/relaton_bib/document_status.rb
170
187
  - lib/relaton_bib/formatted_ref.rb
171
188
  - lib/relaton_bib/formatted_string.rb
189
+ - lib/relaton_bib/hash_to_bib.rb
172
190
  - lib/relaton_bib/localized_string.rb
173
191
  - lib/relaton_bib/medium.rb
174
192
  - lib/relaton_bib/organization.rb
@@ -201,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
219
  version: '0'
202
220
  requirements: []
203
221
  rubyforge_project:
204
- rubygems_version: 2.6.12
222
+ rubygems_version: 2.7.6
205
223
  signing_key:
206
224
  specification_version: 4
207
225
  summary: 'RelatonBib: Ruby XMLDOC impementation.'