relaton-bib 0.3.3 → 0.3.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: c666eff3590a39978b0d0e4547096284b8eedb28c9bb87d819491adc19ad3181
4
- data.tar.gz: 9fe53d79fbca6cb27d0febfbb79981b8cee85ee1f4954db53664bc5f5769394d
2
+ SHA1:
3
+ metadata.gz: ee06437cee7f0efbacf8d04554136258ad4544f4
4
+ data.tar.gz: 3608ad874a15aa0a7c1d2d03270dc02a2a308dfd
5
5
  SHA512:
6
- metadata.gz: e70371f853c3ab10c91cffea4a96453f9929b5979d5947541d8bea21116e236c7eb063968e72ead587af2f0fbd9e3c9a7489e4d83e5c729cbd6571b5ce1f4a2e
7
- data.tar.gz: 96dc61bc07a449c64877fd94e86e9228259c084e5ddef22e4540133b4adc95321caeff297dff3aef3847df5213ffc17d9c874555d7ab13929c6a5e7c7c28abf2
6
+ metadata.gz: 45f05d3a1362dcb45a09c7a04696eb87a48094eaba7314271a519c13c85e83ddbeb85e2c6ccbad8e3f7a064a70c471dc6270684efabce3f2e09374c151fd38ad
7
+ data.tar.gz: 78315011778a04275ff534780f3138bb3f6e2c2476a6f7e7f1ea3287856664dffa80fe678ed0294494a5bed0d1d331c8c1f700d939ba4a7dad813fd435de3a53
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.3.3)
4
+ relaton-bib (0.3.4)
5
5
  addressable
6
6
  nokogiri (~> 1.10)
7
7
 
data/docs/hash.adoc CHANGED
@@ -1,5 +1,7 @@
1
1
  = Relaton YAML
2
2
 
3
+ == YAML
4
+
3
5
  The following structure is in place for encoding bibitem as YAML objects, and is also used
4
6
  to represent bibliographic entries in Metanorma Asciidoctor. The structure has not yet been
5
7
  generalised to `bibdata/ext`, the flavour specific extensions of relaton.
@@ -252,11 +254,14 @@ validity:
252
254
  revision: 2011-03-04 09:00
253
255
  ....
254
256
 
257
+ == Metanorma structure: nested definition list
258
+
255
259
  The Metanorma Asciidoctor representation of this hash structure
256
260
  in a bibliography
257
261
  is as a definition list, with nested definition lists for nested structures.
258
262
  Repeating elements in a hash can be realised as ordered or unordered lists.
259
- However, given how awkward lists of definition lists are in Asciidoctor,
263
+ However, given how awkward lists of definition lists are in Asciidoctor
264
+ (with a limitation of three nesting levels),
260
265
  Metanorma Asciidoctor also supports representing repeating elements
261
266
  by repeating the key for that entry.
262
267
 
@@ -355,20 +360,20 @@ docid::
355
360
  docnumber:: 211
356
361
  edition:: 1
357
362
  language::
358
- * en
359
- * fr
363
+ . en
364
+ . fr
360
365
  script:: Latn
361
366
  version::
362
367
  revision_date::: 2019-04-01
363
368
  draft::: draft
364
369
  biblionote::
365
370
  type::: bibnote
366
- content:::
371
+ content:::
367
372
  +
368
- ---
373
+ --
369
374
  Mark set a major league
370
375
  home run record in 1998.
371
- ---
376
+ --
372
377
  docstatus::
373
378
  stage::: stage
374
379
  substage::: substage
@@ -384,11 +389,11 @@ date::
384
389
  type::: accessed
385
390
  value::: 2015-05-20
386
391
  abstract::
387
- content:::
392
+ content:::
388
393
  +
389
- ---
390
- ISO 19115-1:2014 defines the schema required for ...
391
- ---
394
+ --
395
+ ISO 19115-1:2014 defines the schema required for ...
396
+ --
392
397
  abstract::
393
398
  content::: L'ISO 19115-1:2014 définit le schéma requis pour ...
394
399
  language::: fr
@@ -419,8 +424,8 @@ extent::
419
424
  type::: section
420
425
  reference_from::: 7
421
426
  accesslocation::
422
- * accesslocation1
423
- * accesslocation2
427
+ . accesslocation1
428
+ . accesslocation2
424
429
  classification::
425
430
  type::: type
426
431
  value::: value
@@ -430,12 +435,12 @@ validity::
430
435
 
431
436
 
432
437
  ==== Contributor
433
- person::
438
+ organization::
434
439
  name::: International Organization for Standardization
435
440
  url::: www.iso.org
436
441
  abbreviation::: ISO
437
442
  subdivision::: division
438
- role::
443
+ role::
439
444
  type::: publisher
440
445
  description::: Publisher role
441
446
 
@@ -443,22 +448,25 @@ role::
443
448
  person::
444
449
  name:::
445
450
  completename::::
446
- content::::: A. Bierman
447
- language::::: en
451
+ +
452
+ --
453
+ content:: A. Bierman
454
+ language:: en
455
+ --
448
456
  affiliation:::
449
457
  organization::::
450
- name::::: IETF
451
- abbreviation::::: IETF
452
- identifier:::::
453
458
  +
454
- ---
455
- type:: uri
456
- id:: www.ietf.org
457
- ---
459
+ --
460
+ name:: IETF
461
+ abbreviation:: IETF
462
+ identifier::
463
+ type::: uri
464
+ id::: www.ietf.org
465
+ --
458
466
  description:::: Affiliation description
459
467
  contact:::
460
468
  street::::
461
- * 8 Street St
469
+ . 8 Street St
462
470
  city:::: City
463
471
  postcode:::: 123456
464
472
  country:::: Country
@@ -469,7 +477,7 @@ id:: www.ietf.org
469
477
  role:: author
470
478
 
471
479
  ==== Contributor
472
- person::
480
+ organization::
473
481
  name::: IETF
474
482
  abbreviation::: IETF
475
483
  identifier:::
@@ -484,13 +492,16 @@ person::
484
492
  initial:::: A.
485
493
  surname:::: Bierman
486
494
  affiliation:::
487
- organization::::
488
- name::::: IETF
489
- abbreviation::::: IETF
490
- description::::
491
- content::::: Affiliation description
492
- language::::: en
493
- script::::: Latn
495
+ +
496
+ --
497
+ organization::
498
+ name::: IETF
499
+ abbreviation::: IETF
500
+ description::
501
+ content::: Affiliation description
502
+ language::: en
503
+ script::: Latn
504
+ --
494
505
  identifier:::
495
506
  type:::: uri
496
507
  id:::: www.person.com
@@ -506,8 +517,8 @@ bibitem::
506
517
  reference_to:::: 10
507
518
 
508
519
  ==== Relation
509
- type::: updates
510
- bibitem:::
520
+ type:: updates
521
+ bibitem::
511
522
  type::: standard
512
523
  formattedref::: ISO 19115:2003/Cor 1:2006
513
524
 
@@ -538,7 +549,260 @@ formattedref::
538
549
  script::: Latn
539
550
  ....
540
551
 
552
+ == JSON Path style definition lists
553
+
554
+ The foregoing structure requires frequent breakouts into open blocks, to deal
555
+ with the limitation on Asciidoctor nested definition lists. An alternative is to
556
+ represent the nested structure of Relaton records in a simple, one-level definition list, and to use the key for each key-value pair to represent the hierarchical nesting of entries, as a dot-delimited path of keys. For example,
557
+
558
+ [source,asciidoctor]
559
+ ----
560
+ [%bibitem]
561
+ === Rubber latex -- Sampling
562
+ id:: iso123
563
+ docid::
564
+ type::: ISO
565
+ id::: ISO 123
566
+ ----
567
+
568
+ can instead be represented as:
569
+
570
+ [source,asciidoctor]
571
+ ----
572
+ [%bibitem]
573
+ === Rubber latex -- Sampling
574
+ id:: iso123
575
+ docid.type:: ISO
576
+ docid.id::: ISO 123
577
+ ----
578
+
579
+ Whenever part of the key is repeated between entries, the entries are assumed to attach to the same parent. If an array of hashes is needed, a blank entry is required for the key of each repeating element: For example,
580
+
581
+ [source,asciidoctor]
582
+ ----
583
+ [%bibitem]
584
+ === Rubber latex -- Sampling
585
+ id:: iso123
586
+ docid::
587
+ type::: ISO
588
+ id::: ISO 123
589
+ docid::
590
+ type::: ABC
591
+ id::: 32784
592
+ type:: standard
593
+ ----
594
+
595
+ can instead be represented as:
596
+
597
+ [source,asciidoctor]
598
+ ----
599
+ [%bibitem]
600
+ === Rubber latex -- Sampling
601
+ id:: iso123
602
+ docid::
603
+ docid.type:: ISO
604
+ docid.id::: ISO 123
605
+ docid::
606
+ docid.type:: ABC
607
+ docid.id:: 32784
608
+ ----
609
+
610
+ Embedded elements can also repeat:
611
+
612
+ [source,asciidoctor]
613
+ ----
614
+ [%bibitem]
615
+ ...
616
+ ==== Contributor
617
+ person::
618
+ contact:::
619
+ street::::
620
+ . 8 Street St
621
+ city:::: City
622
+ postcode:::: 123456
623
+ country:::: Country
624
+ state:::: State
625
+ contact:::
626
+ type:::: phone
627
+ value:::: 223322
628
+ ----
541
629
 
630
+ can instead be represented as:
542
631
 
632
+ [source,asciidoctor]
633
+ ----
634
+ [%bibitem]
635
+ ...
636
+ contributor.person.contact::
637
+ contributor.person.contact.street:: 8 Street St
638
+ contributor.person.contact.city:: City
639
+ contributor.person.contact.postcode:: 123456
640
+ contributor.person.contact.country:: Country
641
+ contributor.person.contact.state:: State
642
+ contributor.person.contact::
643
+ contributor.person.contact.type:: phone
644
+ contributor.person.contact.value:: 223322
645
+ ----
543
646
 
647
+ The following is Metanorma Asciidoctor markup corresponding to the YAML
648
+ given above, using JSON Path style definition lists instead of nested definition lists:
544
649
 
650
+ [source,asciidoc]
651
+ ....
652
+ [[ISO/TC211]]
653
+ [%bibitem]
654
+ === {blank}
655
+ fetched:: 2019-06-30
656
+ title::
657
+ title.type:: main
658
+ title.content:: Geographic information
659
+ title::
660
+ title.type:: subtitle
661
+ title.content:: Geographic information subtitle
662
+ title.language:: en
663
+ title.script:: Latn
664
+ title.format:: text/plain
665
+ type:: standard
666
+ docid::
667
+ docid.type:: ISO
668
+ docid.id:: TC211
669
+ docnumber:: 211
670
+ edition:: 1
671
+ language:: en
672
+ language:: fr
673
+ script:: Latn
674
+ version.revision_date:: 2019-04-01
675
+ version.draft:: draft
676
+ biblionote.type:: bibnote
677
+ biblionote.content::
678
+ +
679
+ --
680
+ Mark set a major league
681
+ home run record in 1998.
682
+ --
683
+ docstatus.stage:: stage
684
+ docstatus.substage:: substage
685
+ docstatus.iteration:: iteration
686
+ date::
687
+ date.type:: issued
688
+ date.value:: 2014
689
+ date::
690
+ date.type:: published
691
+ date.from:: 2014-04
692
+ date.to:: 2014-05
693
+ date::
694
+ date.type:: accessed
695
+ date.value:: 2015-05-20
696
+ abstract::
697
+ abstract.content::
698
+ +
699
+ --
700
+ ISO 19115-1:2014 defines the schema required for ...
701
+ --
702
+ abstract::
703
+ abstract.content:: L'ISO 19115-1:2014 définit le schéma requis pour ...
704
+ abstract.language:: fr
705
+ abstract.script:: Latn
706
+ abstract.format:: text/plain
707
+ copyright.owner.name:: International Organization for Standardization
708
+ copyright.owner.abbreviation:: ISO
709
+ copyright.owner.url:: www.iso.org
710
+ copyright.from:: 2014
711
+ copyright.to:: 2020
712
+ link::
713
+ link.type:: src
714
+ link.content:: https://www.iso.org/standard/53798.html
715
+ link::
716
+ link.type:: obp
717
+ link.content:: https://www.iso.org/obp/ui/#!iso:std:53798:en
718
+ link::
719
+ link.type:: rss
720
+ link.content:: https://www.iso.org/contents/data/standard/05/37/53798.detail.rss
721
+ medium::
722
+ medium.form:: medium form
723
+ medium.size:: medium size
724
+ medium.scale:: medium scale
725
+ place:: bib place
726
+ extent.type:: section
727
+ extent.reference_from:: 7
728
+ accesslocation:: accesslocation1
729
+ accesslocation:: accesslocation2
730
+ classification.type:: type
731
+ classification.value:: value
732
+ validity.begins:: 2010-10-10 12:21
733
+ validity.ends:: 2011-02-03 18:30
734
+ contributor::
735
+ contributor.organization.name:: International Organization for Standardization
736
+ contributor.organization.url:: www.iso.org
737
+ contributor.organization.abbreviation:: ISO
738
+ contributor.organization.subdivision:: division
739
+ contributor.role.type:: publisher
740
+ contributor.role.description:: Publisher role
741
+ contributor::
742
+ contributor.person.name.completename.content:: A. Bierman
743
+ contributor.person.name.completename.language:: en
744
+ contributor.person.affiliation.organization.name:: IETF
745
+ contributor.person.affiliation.organization.abbreviation:: IETF
746
+ contributor.person.affiliation.organization.identifier.type:: uri
747
+ contributor.person.affiliation.organization.identifier.id:: www.ietf.org
748
+ contributor.person.affiliation.description:: Affiliation description
749
+ contributor.person.contact::
750
+ contributor.person.contact.street:: 8 Street St
751
+ contributor.person.contact.city:: City
752
+ contributor.person.contact.postcode:: 123456
753
+ contributor.person.contact.country:: Country
754
+ contributor.person.contact.state:: State
755
+ contributor.person.contact::
756
+ contributor.person.contact.type:: phone
757
+ contributor.person.contact.value:: 223322
758
+ contributor.role:: author
759
+ contributor::
760
+ contributor.organization.name:: IETF
761
+ contributor.organization.abbreviation:: IETF
762
+ contributor.organization.identifier.type:: uri
763
+ contributor.organization.identifier.id:: www.ietf.org
764
+ contributor.role:: publisher
765
+ contributor::
766
+ contributor.person.name.language:: en
767
+ contributor.person.name.initial:: A.
768
+ contributor.person.name.surname:: Bierman
769
+ contributor.person.affiliation.organization.name:: IETF
770
+ contributor.person.affiliation.organization.abbreviation:: IETF
771
+ contributor.person.affiliation.description.content:: Affiliation description
772
+ contributor.person.affiliation.description.language:: en
773
+ contributor.person.affiliation.description.script:: Latn
774
+ contributor.person.identifier.type:: uri
775
+ contributor.person.identifier.id:: www.person.com
776
+ contributor.role:: author
777
+ relation::
778
+ relation.type:: updates
779
+ relation.bibitem.formattedref:: ISO 19115:2003
780
+ relation.bibitem.bib_locality.type:: page
781
+ relation.bibitem.bib_locality.reference_from:: 7
782
+ relation.bibitem.bib_locality.reference_to:: 10
783
+ relation::
784
+ relation.type:: updates
785
+ relation.bibitem.type:: standard
786
+ relation.bibitem.formattedref:: ISO 19115:2003/Cor 1:2006
787
+ series::
788
+ series.type:: main
789
+ series.title.type:: original
790
+ series.title.content:: ISO/IEC FDIS 10118-3
791
+ series.title.language:: en
792
+ series.title.script:: Latn
793
+ series.title.format:: text/plain
794
+ series.place:: Serie's place
795
+ series.organization:: Serie's organization
796
+ series.abbreviation.content:: ABVR
797
+ series.abbreviation.language:: en
798
+ series.abbreviation.script:: Latn
799
+ series.from:: 2009-02-01
800
+ series.to:: 2010-12-20
801
+ series.number:: serie1234
802
+ series.partnumber:: part5678
803
+ series::
804
+ series.type:: alt
805
+ series.formattedref.content:: serieref
806
+ series.formattedref.language:: en
807
+ series.formattedref.script:: Latn
808
+ ----
@@ -17,18 +17,18 @@ module RelatonBib
17
17
 
18
18
  # Bibliographic item locality.
19
19
  class BibItemLocality
20
- # @return [RelatonBib::SpecificLocalityType]
20
+ # @return [String]
21
21
  attr_reader :type
22
22
 
23
- # @return [RelatonBib::LocalizedString]
23
+ # @return [String]
24
24
  attr_reader :reference_from
25
25
 
26
- # @return [RelatonBib::LocalizedString]
26
+ # @return [String, NilClass]
27
27
  attr_reader :reference_to
28
28
 
29
29
  # @param type [String]
30
30
  # @param referenceFrom [String]
31
- # @param referenceTo [String]
31
+ # @param referenceTo [String, NilClass]
32
32
  def initialize(type, reference_from, reference_to = nil)
33
33
  @type = type
34
34
  @reference_from = reference_from
@@ -42,5 +42,12 @@ module RelatonBib
42
42
  builder.referenceTo reference_to if reference_to
43
43
  end
44
44
  end
45
+
46
+ # @return [Hash]
47
+ def to_hash
48
+ hash = { type: type, reference_from: reference_from }
49
+ hash[:reference_to] = reference_to if reference_to
50
+ hash
51
+ end
45
52
  end
46
53
  end
@@ -1,13 +1,13 @@
1
1
  module RelatonBib
2
2
  class BiblioNote < FormattedString
3
- # @return [String]
3
+ # @return [String, NilClass]
4
4
  attr_reader :type
5
5
 
6
6
  # @param content [String]
7
- # @param type [String]
8
- # @param language [String] language code Iso639
9
- # @param script [String] script code Iso15924
10
- # @param format [String] the content type
7
+ # @param type [String, NilClass]
8
+ # @param language [String, NilClass] language code Iso639
9
+ # @param script [String, NilClass] script code Iso15924
10
+ # @param format [String, NilClass] the content format
11
11
  def initialize(content:, type: nil, language: nil, script: nil, format: nil)
12
12
  @type = type
13
13
  super content: content, language: language, script: script, format: format
@@ -19,5 +19,12 @@ module RelatonBib
19
19
  xml[:type] = type if type
20
20
  xml
21
21
  end
22
+
23
+ # @return [Hash]
24
+ def to_hash
25
+ hash = super
26
+ hash[:type] = type if type
27
+ hash
28
+ end
22
29
  end
23
30
  end
@@ -2,13 +2,13 @@ module RelatonBib
2
2
  # Version
3
3
  class BibliographicItem
4
4
  class Version
5
- # @return [String]
5
+ # @return [String, NilClass]
6
6
  attr_reader :revision_date
7
7
 
8
8
  # @return [Array<String>]
9
9
  attr_reader :draft
10
10
 
11
- # @param revision_date [String]
11
+ # @param revision_date [String, NilClass]
12
12
  # @param draft [Array<String>]
13
13
  def initialize(revision_date = nil, draft = [])
14
14
  @revision_date = revision_date
@@ -22,6 +22,14 @@ module RelatonBib
22
22
  draft.each { |d| builder.draft d }
23
23
  end
24
24
  end
25
+
26
+ # @return [Hash]
27
+ def to_hash
28
+ hash = {}
29
+ hash[:revision_date] = revision_date if revision_date
30
+ hash[:draft] = draft if draft&.any?
31
+ hash
32
+ end
25
33
  end
26
34
  end
27
35
  end
@@ -12,13 +12,13 @@ module RelatonBib
12
12
  # @return [String]
13
13
  attr_reader :type
14
14
 
15
- # @return [Time]
15
+ # @return [Date]
16
16
  attr_reader :from
17
17
 
18
- # @return [Time]
18
+ # @return [Date]
19
19
  attr_reader :to
20
20
 
21
- # @return [Time]
21
+ # @return [Date]
22
22
  attr_reader :on
23
23
 
24
24
  # @param type [String] "published", "accessed", "created", "activated"
@@ -52,6 +52,15 @@ module RelatonBib
52
52
  end
53
53
  # rubocop:enable Metrics/AbcSize
54
54
 
55
+ # @return [Hash]
56
+ def to_hash
57
+ hash = { type: type }
58
+ hash[:value] = on.to_s if on
59
+ hash[:from] = from.to_s if from
60
+ hash[:to] = to.to_s if to
61
+ hash
62
+ end
63
+
55
64
  private
56
65
 
57
66
  # Formats date
@@ -67,16 +76,16 @@ module RelatonBib
67
76
  end
68
77
 
69
78
  # @params date [String] 'yyyy', 'yyyy-mm', 'yyyy-mm-dd
70
- # @return [Time]
79
+ # @return [Date]
71
80
  def parse_date(date)
72
81
  return unless date
73
82
 
74
83
  if date =~ /^\d{4}$/
75
- Time.strptime date, "%Y"
84
+ Date.strptime date, "%Y"
76
85
  elsif date =~ /^\d{4}-\d{2}$/
77
- Time.strptime date, "%Y-%m"
86
+ Date.strptime date, "%Y-%m"
78
87
  elsif date =~ /\d{4}-\d{2}-\d{2}$/
79
- Time.strptime date, "%Y-%m-%d"
88
+ Date.strptime date, "%Y-%m-%d"
80
89
  end
81
90
  end
82
91
  end
@@ -32,7 +32,7 @@ module RelatonBib
32
32
  inbook incollection inproceedings journal
33
33
  ].freeze
34
34
 
35
- # @return [String]
35
+ # @return [String, NilClass]
36
36
  attr_reader :id
37
37
 
38
38
  # @return [Array<RelatonBib::TypedTitleString>]
@@ -41,13 +41,13 @@ module RelatonBib
41
41
  # @return [Array<RelatonBib::TypedUri>]
42
42
  attr_reader :link
43
43
 
44
- # @return [String]
44
+ # @return [String, NilClass]
45
45
  attr_reader :type
46
46
 
47
47
  # @return [Array<RelatonBib::DocumentIdentifier>]
48
48
  attr_reader :docidentifier
49
49
 
50
- # @return [String] docnumber
50
+ # @return [String, NilClass] docnumber
51
51
  attr_reader :docnumber
52
52
 
53
53
  # @return [Array<RelatonBib::BibliographicDate>]
@@ -59,10 +59,10 @@ module RelatonBib
59
59
  # @return [String, NillClass]
60
60
  attr_reader :edition
61
61
 
62
- # @return [RelatonBib::BibliongraphicItem::Version]
62
+ # @return [RelatonBib::BibliongraphicItem::Version, NilClass]
63
63
  attr_reader :version
64
64
 
65
- # @return [Array<RelatonBib::BiblioNote>, NilClass]
65
+ # @return [Array<RelatonBib::BiblioNote>]
66
66
  attr_reader :biblionote
67
67
 
68
68
  # @return [Array<String>] language Iso639 code
@@ -71,7 +71,7 @@ module RelatonBib
71
71
  # @return [Array<String>] script Iso15924 code
72
72
  attr_reader :script
73
73
 
74
- # @return [RelatonBib::FormattedRef]
74
+ # @return [RelatonBib::FormattedRef, NilClass]
75
75
  attr_reader :formattedref
76
76
 
77
77
  # @!attribute [r] abstract
@@ -80,7 +80,7 @@ module RelatonBib
80
80
  # @return [RelatonBib::DocumentStatus, NilClass]
81
81
  attr_reader :status
82
82
 
83
- # @return [RelatonBib::CopyrightAssociation]
83
+ # @return [RelatonBib::CopyrightAssociation, NilClass]
84
84
  attr_reader :copyright
85
85
 
86
86
  # @return [RelatonBib::DocRelationCollection]
@@ -134,6 +134,11 @@ module RelatonBib
134
134
  # @param validity [RelatonBib:Validity, NilClass]
135
135
  # @param fetched [Date, NilClass] default nil
136
136
  #
137
+ # @param copyright [Hash, RelatonBib::CopyrightAssociation, NilClass]
138
+ # @option copyright [Hash, RelatonBib::ContributionInfo] :owner
139
+ # @option copyright [String] :form
140
+ # @option copyright [String, NilClass] :to
141
+ #
137
142
  # @param date [Array<Hash>]
138
143
  # @option date [String] :type
139
144
  # @option date [String] :from
@@ -265,6 +270,38 @@ module RelatonBib
265
270
  end
266
271
  end
267
272
 
273
+ # @return [Hash]
274
+ def to_hash
275
+ hash = {}
276
+ hash[:id] = id if id
277
+ hash[:title] = title.map(&:to_hash) if title&.any?
278
+ hash[:link] = link.map(&:to_hash) if link&.any?
279
+ hash[:type] = type if type
280
+ hash[:docid] = docidentifier.map(&:to_hash) if docidentifier&.any?
281
+ hash[:docnumber] = docnumber if docnumber
282
+ hash[:date] = date.map(&:to_hash) if date&.any?
283
+ hash[:contributor] = contributor.map(&:to_hash) if contributor&.any?
284
+ hash[:edition] = edition if edition
285
+ hash[:version] = version.to_hash if version
286
+ hash[:biblionote] = biblionote.map(&:to_hash) if biblionote&.any?
287
+ hash[:language] = language if language&.any?
288
+ hash[:script] = script if script&.any?
289
+ hash[:formattedref] = formattedref.to_hash if formattedref
290
+ hash[:abstract] = abstract.map(&:to_hash) if abstract&.any?
291
+ hash[:docstatus] = status.to_hash if status
292
+ hash[:copyright] = copyright.to_hash if copyright
293
+ hash[:relation] = relation.map(&:to_hash) if relation&.any?
294
+ hash[:series] = series.map(&:to_hash) if series&.any?
295
+ hash[:medium] = medium.to_hash if medium
296
+ hash[:place] = place if place&.any?
297
+ hash[:extent] = extent.map(&:to_hash) if extent&.any?
298
+ hash[:accesslocation] = accesslocation if accesslocation&.any?
299
+ hash[:classification] = classification.to_hash if classification
300
+ hash[:validity] = validity.to_hash if validity
301
+ hash[:fetched] = fetched.to_s if fetched
302
+ hash
303
+ end
304
+
268
305
  private
269
306
 
270
307
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@@ -18,5 +18,12 @@ module RelatonBib
18
18
  xml = builder.classification value
19
19
  xml[:type] = type if type
20
20
  end
21
+
22
+ # @return [Hash]
23
+ def to_hash
24
+ hash = { value: value }
25
+ hash[:type] = type if type
26
+ hash
27
+ end
21
28
  end
22
29
  end
@@ -36,6 +36,15 @@ module RelatonBib
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ # @return [Array]
41
+ def to_hash
42
+ if description&.any?
43
+ [type, description.map(&:content)] if type
44
+ else
45
+ type if type
46
+ end
47
+ end
39
48
  end
40
49
 
41
50
  # Contribution info.
@@ -54,8 +63,16 @@ module RelatonBib
54
63
  @role = role.map { |r| ContributorRole.new(**r) }
55
64
  end
56
65
 
66
+ # @param builder [Nokogiri::XML::Builder]
57
67
  def to_xml(builder)
58
68
  entity.to_xml builder
59
69
  end
70
+
71
+ # @return [Hash]
72
+ def to_hash
73
+ hash = entity.to_hash
74
+ hash[:role] = role.map(&:to_hash) if role&.any?
75
+ hash
76
+ end
60
77
  end
61
78
  end
@@ -43,6 +43,17 @@ module RelatonBib
43
43
  doc.postcode postcode if postcode
44
44
  end
45
45
  end
46
+
47
+ # @return [Hash]
48
+ def to_hash
49
+ hash = {}
50
+ hash[:street] = street if street&.any?
51
+ hash[:city] = city
52
+ hash[:state] = state if state
53
+ hash[:country] = country
54
+ hash[:postcode] = postcode if postcode
55
+ hash
56
+ end
46
57
  end
47
58
 
48
59
  # Contact class.
@@ -63,11 +74,16 @@ module RelatonBib
63
74
  def to_xml(doc)
64
75
  doc.send type, value
65
76
  end
77
+
78
+ # @return [Hash]
79
+ def to_hash
80
+ { type: type, value: value }
81
+ end
66
82
  end
67
83
 
68
84
  # Affilation.
69
85
  class Affilation
70
- # @return [RelatonBib::LocalizedString]
86
+ # @return [RelatonBib::LocalizedString, NilClass]
71
87
  attr_reader :name
72
88
 
73
89
  # @return [Array<RelatonBib::FormattedString>]
@@ -77,8 +93,10 @@ module RelatonBib
77
93
  attr_reader :organization
78
94
 
79
95
  # @param organization [RelatonBib::Organization]
96
+ # @param name [RelatonBib::LocalizedString, NilClass]
80
97
  # @param description [Array<RelatonBib::FormattedString>]
81
- def initialize(organization, description = [])
98
+ def initialize(organization:, name: nil, description: [])
99
+ @name = name
82
100
  @organization = organization
83
101
  @description = description
84
102
  end
@@ -91,6 +109,14 @@ module RelatonBib
91
109
  organization.to_xml builder
92
110
  end
93
111
  end
112
+
113
+ # @return [Hash]
114
+ def to_hash
115
+ hash = organization.to_hash
116
+ hash[:name] = name.to_hash if name
117
+ hash[:description] = description.map(&:to_hash) if description&.any?
118
+ hash
119
+ end
94
120
  end
95
121
 
96
122
  # Contributor.
@@ -98,11 +124,11 @@ module RelatonBib
98
124
  # @return [URI]
99
125
  attr_reader :uri
100
126
 
101
- # @return [Array<RelatonBib::Address, RelatonBib::Phone>]
127
+ # @return [Array<RelatonBib::Address, RelatonBib::Contact>]
102
128
  attr_reader :contact
103
129
 
104
130
  # @param url [String]
105
- # @param contact [Array<RelatonBib::Address, RelatonBib::Phone>]
131
+ # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
106
132
  def initialize(url: nil, contact: [])
107
133
  @uri = URI url if url
108
134
  @contact = contact
@@ -118,5 +144,13 @@ module RelatonBib
118
144
  def to_xml(builder)
119
145
  contact.each { |contact| contact.to_xml builder }
120
146
  end
147
+
148
+ # @return [Hash]
149
+ def to_hash
150
+ hash = {}
151
+ hash[:url] = uri.to_s if uri
152
+ hash[:contact] = contact.map(&:to_hash) if contact&.any?
153
+ hash
154
+ end
121
155
  end
122
156
  end
@@ -1,10 +1,10 @@
1
1
  module RelatonBib
2
2
  # Copyright association.
3
3
  class CopyrightAssociation
4
- # @return [Time]
4
+ # @return [Date]
5
5
  attr_reader :from
6
6
 
7
- # @return [Time]
7
+ # @return [Date, NilClass]
8
8
  attr_reader :to
9
9
 
10
10
  # @return [RelatonBib::ContributionInfo]
@@ -22,8 +22,8 @@ module RelatonBib
22
22
  else owner
23
23
  end
24
24
 
25
- @from = Time.strptime(from, "%Y") unless from.empty?
26
- @to = Time.strptime(to, "%Y") unless to.to_s.empty?
25
+ @from = Date.strptime(from, "%Y") unless from.empty?
26
+ @to = Date.strptime(to, "%Y") unless to.to_s.empty?
27
27
  end
28
28
 
29
29
  # @param builder [Nokogiri::XML::Builder]
@@ -34,5 +34,12 @@ module RelatonBib
34
34
  builder.owner { owner.to_xml builder }
35
35
  end
36
36
  end
37
+
38
+ # @return [Hash]
39
+ def to_hash
40
+ hash = { owner: owner.to_hash[:organization], from: from.to_s }
41
+ hash[:to] = to.to_s if to
42
+ hash
43
+ end
37
44
  end
38
45
  end
@@ -43,5 +43,12 @@ module RelatonBib
43
43
  def to_xml(builder)
44
44
  builder.docidentifier(id, type: type)
45
45
  end
46
+
47
+ # @return [Hash]
48
+ def to_hash
49
+ hash = { id: id }
50
+ hash[:type] if type
51
+ hash
52
+ end
46
53
  end
47
54
  end
@@ -47,5 +47,12 @@ module RelatonBib
47
47
  end
48
48
  end
49
49
  end
50
+
51
+ # @return [Hash]
52
+ def to_hash
53
+ hash = { type: type, bibitem: bibitem.to_hash }
54
+ hash[:bib_locality] = bib_locality.map(&:to_hash) if bib_locality&.any?
55
+ hash
56
+ end
50
57
  end
51
58
  end
@@ -32,5 +32,13 @@ module RelatonBib
32
32
  builder.iteration iteration unless iteration.to_s.empty?
33
33
  end
34
34
  end
35
+
36
+ # @return [Hash]
37
+ def to_hash
38
+ hash = { stage: stage }
39
+ hash[:substage] = substage if substage
40
+ hash[:iteration] = iteration if iteration
41
+ hash
42
+ end
35
43
  end
36
44
  end
@@ -30,5 +30,12 @@ module RelatonBib
30
30
  builder.parent["format"] = format if format
31
31
  super
32
32
  end
33
+
34
+ # @return [Hash]
35
+ def to_hash
36
+ hash = super
37
+ hash[:format] = format if format
38
+ hash
39
+ end
33
40
  end
34
41
  end
@@ -198,7 +198,9 @@ module RelatonBib
198
198
  { content: d })
199
199
  end
200
200
  Affilation.new(
201
- Organization.new(org_hash_to_bib(a[:organization])), a[:description])
201
+ organization: Organization.new(org_hash_to_bib(a[:organization])),
202
+ description: a[:description]
203
+ )
202
204
  end
203
205
  end
204
206
 
@@ -215,6 +217,7 @@ module RelatonBib
215
217
 
216
218
  def relations_hash_to_bib(ret)
217
219
  return unless ret[:relation]
220
+
218
221
  ret[:relation] = array(ret[:relation])
219
222
  ret[:relation]&.each_with_index do |r, i|
220
223
  relation_bibitem_hash_to_bib(ret, r, i)
@@ -222,15 +225,24 @@ module RelatonBib
222
225
  end
223
226
  end
224
227
 
228
+ # @param ret [Hash]
229
+ # @param r [Hash] relation
230
+ # @param i [Integr] index of relation
225
231
  def relation_bibitem_hash_to_bib(ret, r, i)
226
- if r[:bibitem] then ret[:relation][i][:bibitem] =
227
- BibliographicItem.new(hash_to_bib(r[:bibitem], true))
232
+ if r[:bibitem]
233
+ ret[:relation][i][:bibitem] = bib_item(hash_to_bib(r[:bibitem], true))
228
234
  else
229
235
  warn "bibitem missing: #{r}"
230
236
  ret[:relation][i][:bibitem] = nil
231
237
  end
232
238
  end
233
239
 
240
+ # @param item [Hash]
241
+ # @retirn [RelatonBib::BibliographicItem]
242
+ def bib_item(item)
243
+ BibliographicItem.new(item)
244
+ end
245
+
234
246
  def relation_biblocality_hash_to_bib(ret, r, i)
235
247
  ret[:relation][i][:bib_locality] =
236
248
  array(r[:bib_locality])&.map do |bl|
@@ -244,7 +256,7 @@ module RelatonBib
244
256
  s[:formattedref] and s[:formattedref] = formattedref(s[:formattedref])
245
257
  if s[:title]
246
258
  s[:title] = { content: s[:title] } unless s.is_a?(Hash)
247
- s[:title] = TypedTitleString.new(s[:title])
259
+ s[:title] = typed_title_strig(s[:title])
248
260
  end
249
261
  s[:abbreviation] and
250
262
  s[:abbreviation] = localizedstring(s[:abbreviation])
@@ -252,15 +264,21 @@ module RelatonBib
252
264
  end
253
265
  end
254
266
 
267
+ # @param title [Hash]
268
+ # @return [RelatonBib::TypedTitleString]
269
+ def typed_title_strig(title)
270
+ TypedTitleString.new title
271
+ end
272
+
255
273
  def medium_hash_to_bib(ret)
256
274
  ret[:medium] and ret[:medium] = Medium.new(ret[:medium])
257
275
  end
258
276
 
259
277
  def classification_hash_to_bib(ret)
260
- #ret[:classification] = [ret[:classification]] unless ret[:classification].is_a?(Array)
261
- #ret[:classification]&.each_with_index do |c, i|
262
- #ret[:classification][i] = RelatonBib::Classification.new(c)
263
- #end
278
+ # ret[:classification] = [ret[:classification]] unless ret[:classification].is_a?(Array)
279
+ # ret[:classification]&.each_with_index do |c, i|
280
+ # ret[:classification][i] = RelatonBib::Classification.new(c)
281
+ # end
264
282
  ret[:classification] and
265
283
  ret[:classification] = Classification.new(ret[:classification])
266
284
  end
@@ -16,10 +16,8 @@ module RelatonBib
16
16
  # @param language [String] language code Iso639
17
17
  # @param script [String] script code Iso15924
18
18
  def initialize(content, language = nil, script = nil)
19
- @language = []
20
- @language << language if language
21
- @script = []
22
- @script << script if script
19
+ @language = language.is_a?(String) ? [language] : language
20
+ @script = script.is_a?(String) ? [script] : script
23
21
  @content = content
24
22
  end
25
23
 
@@ -37,9 +35,17 @@ module RelatonBib
37
35
  def to_xml(builder)
38
36
  return unless content
39
37
 
40
- builder.parent["language"] = language.join(",") if language.any?
41
- builder.parent["script"] = script.join(",") if script.any?
38
+ builder.parent["language"] = language.join(",") if language&.any?
39
+ builder.parent["script"] = script.join(",") if script&.any?
42
40
  builder.text content
43
41
  end
42
+
43
+ # @return [Hash]
44
+ def to_hash
45
+ hash = { content: content }
46
+ hash[:language] = language if language&.any?
47
+ hash[:script] = script if script&.any?
48
+ hash
49
+ end
44
50
  end
45
51
  end
@@ -20,5 +20,14 @@ module RelatonBib
20
20
  builder.scale scale if scale
21
21
  end
22
22
  end
23
+
24
+ # @return [Hash]
25
+ def to_hash
26
+ hash = {}
27
+ hash[:form] = form if form
28
+ hash[:size] = size if size
29
+ hash[:scale] = scale if scale
30
+ hash
31
+ end
23
32
  end
24
33
  end
@@ -34,6 +34,11 @@ module RelatonBib
34
34
  def to_xml(builder)
35
35
  builder.identifier(value, type: type)
36
36
  end
37
+
38
+ # @return [Hash]
39
+ def to_hash
40
+ { type: type, id: value }
41
+ end
37
42
  end
38
43
 
39
44
  # Organization.
@@ -41,10 +46,10 @@ module RelatonBib
41
46
  # @return [Array<RelatonBib::LocalizedString>]
42
47
  attr_reader :name
43
48
 
44
- # @return [RelatonBib::LocalizedString]
49
+ # @return [RelatonBib::LocalizedString, NilClass]
45
50
  attr_reader :abbreviation
46
51
 
47
- # @return [RelatonBib::LocalizedString]
52
+ # @return [RelatonBib::LocalizedString, NilClass]
48
53
  attr_reader :subdivision
49
54
 
50
55
  # @return [Array<RelatonBib::OrgIdentifier>]
@@ -61,7 +66,7 @@ module RelatonBib
61
66
  # @param subdivision [RelatoBib::LocalizedStrig, String]
62
67
  # @param url [String]
63
68
  # @param identifier [Array<RelatonBib::OrgIdentifier>]
64
- # @param contact [Array<RelatonBib::Address, RelatonBib::Phone>]
69
+ # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
65
70
  def initialize(**args)
66
71
  raise ArgumentError, "missing keyword: name" unless args[:name]
67
72
 
@@ -101,5 +106,14 @@ module RelatonBib
101
106
  super
102
107
  end
103
108
  end
109
+
110
+ # @return [Hash]
111
+ def to_hash
112
+ hash = { name: name.map(&:to_hash) }
113
+ hash[:abbreviation] = abbreviation.to_hash if abbreviation
114
+ hash[:identifier] = identifier.map(&:to_hash) if identifier&.any?
115
+ hash[:subdivision] = subdivision.to_hash if subdivision
116
+ { organization: hash.merge(super) }
117
+ end
104
118
  end
105
119
  end
@@ -56,6 +56,27 @@ module RelatonBib
56
56
  end
57
57
  end
58
58
  end
59
+
60
+ # @return [Hash]
61
+ def to_hash
62
+ hash = {}
63
+ hash[:forename] = forename.map(&:to_hash) if forename&.any?
64
+ hash[:initial] = initial.map(&:to_hash) if initial&.any?
65
+ hash[:surname] = surname.to_hash if surname
66
+ hash[:addition] = addition.map(&:to_hash) if addition&.any?
67
+ hash[:prefix] = prefix.map(&:to_hash) if prefix&.any?
68
+ hash[:completename] = completename.to_hash if completename
69
+ hash
70
+ # instance_variables.reduce({}) do |hash, var|
71
+ # val = instance_variable_get var
72
+ # if val || val.is_a?(Array) && val.any?
73
+ # key = var.to_s.sub("@", "").to_sym
74
+ # hash.merge key => val
75
+ # else
76
+ # hash
77
+ # end
78
+ # end
79
+ end
59
80
  end
60
81
 
61
82
  # Person identifier type.
@@ -94,6 +115,11 @@ module RelatonBib
94
115
  def to_xml(builder)
95
116
  builder.identifier value, type: type
96
117
  end
118
+
119
+ # @return [Hash]
120
+ def to_hash
121
+ { type: type, id: value }
122
+ end
97
123
  end
98
124
 
99
125
  # Person class.
@@ -109,7 +135,7 @@ module RelatonBib
109
135
 
110
136
  # @param name [RelatonBib::FullName]
111
137
  # @param affiliation [Array<RelatonBib::Affiliation>]
112
- # @param contact [Array<RelatonBib::Address, RelatonBib::Phone>]
138
+ # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
113
139
  # @param identifier [Array<RelatonBib::PersonIdentifier>]
114
140
  def initialize(name:, affiliation: [], contact: [], identifier: [])
115
141
  super(contact: contact)
@@ -127,5 +153,13 @@ module RelatonBib
127
153
  contact.each { |contact| contact.to_xml builder }
128
154
  end
129
155
  end
156
+
157
+ # @return [Hash]
158
+ def to_hash
159
+ hash = { name: name.to_hash }
160
+ hash[:affiliation] = affiliation.map(&:to_hash) if affiliation&.any?
161
+ hash[:identifier] = identifier.map(&:to_hash) if identifier&.any?
162
+ { person: hash.merge(super) }
163
+ end
130
164
  end
131
165
  end
@@ -93,5 +93,21 @@ module RelatonBib
93
93
  end
94
94
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
95
95
  # rubocop:enable Metrics/PerceivedComplexity
96
+
97
+ # @return [Hash]
98
+ def to_hash
99
+ hash = {}
100
+ hash[:type] = type if type
101
+ hash[:formattedref] = formattedref.to_hash if formattedref
102
+ hash[:title] = title.to_hash if title
103
+ hash[:place] = place if place
104
+ hash[:organization] = organization if organization
105
+ hash[:abbreviation] = abbreviation.to_hash if abbreviation
106
+ hash[:from] = from if from
107
+ hash[:to] = to if to
108
+ hash[:number] = number if number
109
+ hash[:partnumber] = partnumber if partnumber
110
+ hash
111
+ end
96
112
  end
97
113
  end
@@ -42,5 +42,12 @@ module RelatonBib
42
42
  builder.parent[:type] = type if type
43
43
  title.to_xml builder
44
44
  end
45
+
46
+ # @return [Hash]
47
+ def to_hash
48
+ hash = {}
49
+ hash[:type] = type if type
50
+ hash.merge title.to_hash
51
+ end
45
52
  end
46
53
  end
@@ -15,8 +15,14 @@ module RelatonBib
15
15
  @content = Addressable::URI.parse content if content
16
16
  end
17
17
 
18
+ # @param builder [Nokogiri::XML::Builder]
18
19
  def to_xml(builder)
19
20
  builder.uri(content.to_s, type: type)
20
21
  end
22
+
23
+ # @return [Hash]
24
+ def to_hash
25
+ { type: type, content: content.to_s }
26
+ end
21
27
  end
22
28
  end
@@ -1,5 +1,7 @@
1
1
  module RelatonBib
2
2
  class Validity
3
+ FORMAT = "%Y-%m-%d %H:%M"
4
+
3
5
  # @return [Time, NilClass]
4
6
  attr_reader :begins
5
7
 
@@ -20,12 +22,20 @@ module RelatonBib
20
22
 
21
23
  # @param [Nokogiri::XML::Builder]
22
24
  def to_xml(builder)
23
- format = "%Y-%m-%d %H:%M"
24
25
  builder.validity do
25
- builder.validityBegins begins.strftime(format) if begins
26
- builder.validityEnds ends.strftime(format) if ends
27
- builder.validityRevision revision.strftime(format) if revision
26
+ builder.validityBegins begins.strftime(FORMAT) if begins
27
+ builder.validityEnds ends.strftime(FORMAT) if ends
28
+ builder.validityRevision revision.strftime(FORMAT) if revision
28
29
  end
29
30
  end
31
+
32
+ # @return [Hash]
33
+ def to_hash
34
+ hash = {}
35
+ hash[:begins] = begins.strftime(FORMAT) if begins
36
+ hash[:ends] = ends.strftime(FORMAT) if ends
37
+ hash[:revision] = revision.strftime(FORMAT) if revision
38
+ hash
39
+ end
30
40
  end
31
41
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.3.3".freeze
2
+ VERSION = "0.3.4".freeze
3
3
  end
@@ -178,7 +178,11 @@ module RelatonBib
178
178
  def get_person(person)
179
179
  affilations = person.xpath("./affiliation").map do |a|
180
180
  org = a.at "./organization"
181
- Affilation.new get_org(org)
181
+ desc = a.xpath("./description").map do |e|
182
+ FormattedString.new(content: e.text, language: e[:language],
183
+ script: e[:script], format: e[:format])
184
+ end
185
+ Affilation.new organization: get_org(org), description: desc
182
186
  end
183
187
 
184
188
  contact = person.xpath("./address | ./phone | ./email | ./uri").map do |c|
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.3.3
4
+ version: 0.3.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-08-03 00:00:00.000000000 Z
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  requirements: []
222
222
  rubyforge_project:
223
- rubygems_version: 2.7.6
223
+ rubygems_version: 2.6.12
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: 'RelatonBib: Ruby XMLDOC impementation.'