relaton-bib 1.4.0 → 2.1.7

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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration-tests.yml +54 -0
  3. data/.github/workflows/rake.yml +15 -0
  4. data/.github/workflows/release.yml +24 -0
  5. data/.gitignore +4 -1
  6. data/.rubocop.yml +3 -1
  7. data/CLAUDE.md +108 -0
  8. data/Gemfile +11 -0
  9. data/README.adoc +229 -314
  10. data/bin/console +1 -1
  11. data/docs/hash.adoc +132 -83
  12. data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
  13. data/lib/relaton/bib/converter/asciibib.rb +13 -0
  14. data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
  15. data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
  16. data/lib/relaton/bib/converter/bibtex.rb +23 -0
  17. data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +386 -0
  18. data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
  19. data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +308 -0
  20. data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
  21. data/lib/relaton/bib/converter/bibxml.rb +51 -0
  22. data/lib/relaton/bib/hash_parser_v1.rb +767 -0
  23. data/lib/relaton/bib/item_data.rb +229 -0
  24. data/lib/relaton/bib/model/abstract.rb +16 -0
  25. data/lib/relaton/bib/model/address.rb +22 -0
  26. data/lib/relaton/bib/model/affiliation.rb +16 -0
  27. data/lib/relaton/bib/model/bibdata.rb +9 -0
  28. data/lib/relaton/bib/model/bibdata_shared.rb +10 -0
  29. data/lib/relaton/bib/model/bibitem.rb +9 -0
  30. data/lib/relaton/bib/model/bibitem_shared.rb +10 -0
  31. data/lib/relaton/bib/model/contact.rb +14 -0
  32. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  33. data/lib/relaton/bib/model/contributor.rb +29 -0
  34. data/lib/relaton/bib/model/copyright.rb +27 -0
  35. data/lib/relaton/bib/model/date.rb +29 -0
  36. data/lib/relaton/bib/model/depiction.rb +16 -0
  37. data/lib/relaton/bib/model/docidentifier.rb +34 -0
  38. data/lib/relaton/bib/model/doctype.rb +14 -0
  39. data/lib/relaton/bib/model/edition.rb +14 -0
  40. data/lib/relaton/bib/model/ext.rb +35 -0
  41. data/lib/relaton/bib/model/extent.rb +16 -0
  42. data/lib/relaton/bib/model/formattedref.rb +43 -0
  43. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  44. data/lib/relaton/bib/model/fullname.rb +11 -0
  45. data/lib/relaton/bib/model/ics.rb +49 -0
  46. data/lib/relaton/bib/model/image.rb +28 -0
  47. data/lib/relaton/bib/model/item.rb +44 -0
  48. data/lib/relaton/bib/model/item_base.rb +20 -0
  49. data/lib/relaton/bib/model/item_shared.rb +88 -0
  50. data/lib/relaton/bib/model/keyword.rb +30 -0
  51. data/lib/relaton/bib/model/locality.rb +18 -0
  52. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  53. data/lib/relaton/bib/model/localized_string.rb +48 -0
  54. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  55. data/lib/relaton/bib/model/logo.rb +14 -0
  56. data/lib/relaton/bib/model/medium.rb +22 -0
  57. data/lib/relaton/bib/model/note.rb +16 -0
  58. data/lib/relaton/bib/model/organization.rb +11 -0
  59. data/lib/relaton/bib/model/organization_type.rb +40 -0
  60. data/lib/relaton/bib/model/person.rb +36 -0
  61. data/lib/relaton/bib/model/phone.rb +14 -0
  62. data/lib/relaton/bib/model/place.rb +33 -0
  63. data/lib/relaton/bib/model/price.rb +14 -0
  64. data/lib/relaton/bib/model/relation.rb +41 -0
  65. data/lib/relaton/bib/model/series.rb +32 -0
  66. data/lib/relaton/bib/model/size.rb +23 -0
  67. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  68. data/lib/relaton/bib/model/status.rb +27 -0
  69. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  70. data/lib/relaton/bib/model/subdivision.rb +16 -0
  71. data/lib/relaton/bib/model/title.rb +56 -0
  72. data/lib/relaton/bib/model/type/plain_date.rb +16 -0
  73. data/lib/relaton/bib/model/type/string_date.rb +48 -0
  74. data/lib/relaton/bib/model/uri.rb +18 -0
  75. data/lib/relaton/bib/model/validity.rb +16 -0
  76. data/lib/relaton/bib/model/version.rb +43 -0
  77. data/lib/relaton/bib/model_autoload.rb +85 -0
  78. data/lib/relaton/bib/namespace_helper.rb +21 -0
  79. data/lib/relaton/bib/sanitizer.rb +74 -0
  80. data/lib/relaton/bib/util.rb +18 -0
  81. data/lib/relaton/bib/version.rb +5 -0
  82. data/lib/relaton/bib/versions.json +35 -0
  83. data/lib/relaton/bib.rb +41 -0
  84. data/relaton-bib.gemspec +12 -16
  85. metadata +118 -129
  86. data/.github/workflows/macos.yml +0 -38
  87. data/.github/workflows/ubuntu.yml +0 -39
  88. data/.github/workflows/windows.yml +0 -41
  89. data/grammars/basicdoc.rng +0 -986
  90. data/grammars/biblio.rng +0 -1237
  91. data/grammars/isodoc.rng +0 -1613
  92. data/grammars/reqt.rng +0 -165
  93. data/lib/relaton_bib/bib_item_locality.rb +0 -107
  94. data/lib/relaton_bib/biblio_note.rb +0 -44
  95. data/lib/relaton_bib/biblio_version.rb +0 -49
  96. data/lib/relaton_bib/bibliographic_date.rb +0 -90
  97. data/lib/relaton_bib/bibliographic_item.rb +0 -726
  98. data/lib/relaton_bib/bibtex_parser.rb +0 -245
  99. data/lib/relaton_bib/classification.rb +0 -40
  100. data/lib/relaton_bib/contribution_info.rb +0 -109
  101. data/lib/relaton_bib/contributor.rb +0 -215
  102. data/lib/relaton_bib/copyright_association.rb +0 -77
  103. data/lib/relaton_bib/deep_dup.rb +0 -30
  104. data/lib/relaton_bib/document_identifier.rb +0 -95
  105. data/lib/relaton_bib/document_relation.rb +0 -94
  106. data/lib/relaton_bib/document_relation_collection.rb +0 -46
  107. data/lib/relaton_bib/document_status.rb +0 -93
  108. data/lib/relaton_bib/editorial_group.rb +0 -41
  109. data/lib/relaton_bib/formatted_ref.rb +0 -17
  110. data/lib/relaton_bib/formatted_string.rb +0 -55
  111. data/lib/relaton_bib/hash_converter.rb +0 -497
  112. data/lib/relaton_bib/hit.rb +0 -46
  113. data/lib/relaton_bib/hit_collection.rb +0 -73
  114. data/lib/relaton_bib/ics.rb +0 -37
  115. data/lib/relaton_bib/localized_string.rb +0 -93
  116. data/lib/relaton_bib/medium.rb +0 -44
  117. data/lib/relaton_bib/organization.rb +0 -135
  118. data/lib/relaton_bib/person.rb +0 -206
  119. data/lib/relaton_bib/place.rb +0 -49
  120. data/lib/relaton_bib/series.rb +0 -134
  121. data/lib/relaton_bib/structured_identifier.rb +0 -171
  122. data/lib/relaton_bib/technical_committee.rb +0 -36
  123. data/lib/relaton_bib/typed_title_string.rb +0 -96
  124. data/lib/relaton_bib/typed_uri.rb +0 -47
  125. data/lib/relaton_bib/validity.rb +0 -52
  126. data/lib/relaton_bib/version.rb +0 -3
  127. data/lib/relaton_bib/workers_pool.rb +0 -43
  128. data/lib/relaton_bib/workgroup.rb +0 -46
  129. data/lib/relaton_bib/xml_parser.rb +0 -463
  130. data/lib/relaton_bib.rb +0 -44
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RelatonBib
4
- # Localized string.
5
- class LocalizedString
6
- include RelatonBib
7
-
8
- # @return [Array<String>] language Iso639 code
9
- attr_reader :language
10
-
11
- # @return [Array<String>] script Iso15924 code
12
- attr_reader :script
13
-
14
- # @return [String, Array<RelatonBib::LocalizedString>]
15
- attr_accessor :content
16
-
17
- # @param content [String, Array<RelatonBib::LocalizedString>]
18
- # @param language [String] language code Iso639
19
- # @param script [String] script code Iso15924
20
- def initialize(content, language = nil, script = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
21
- if content.is_a? Array
22
- inv = content.reject { |c| c.is_a?(LocalizedString) || c.is_a?(Hash) }
23
- end
24
- unless content.is_a?(String) || inv&.none? && content.any?
25
- klass = content.is_a?(Array) ? inv.first.class : content.class
26
- raise ArgumentError, "invalid LocalizedString content type: #{klass}"
27
- end
28
- @language = language.is_a?(String) ? [language] : language
29
- @script = script.is_a?(String) ? [script] : script
30
- @content = if content.is_a?(Array)
31
- content.map do |c|
32
- if c.is_a?(Hash)
33
- LocalizedString.new c[:content], c[:language], c[:script]
34
- else c
35
- end
36
- end
37
- else content
38
- end
39
- end
40
-
41
- # @return [String]
42
- def to_s
43
- content.is_a?(String) ? content : content.first.to_s
44
- end
45
-
46
- # @return [TrueClass, FalseClass]
47
- def empty?
48
- content.empty?
49
- end
50
-
51
- # @param builder [Nokogiri::XML::Builder]
52
- def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
53
- return unless content
54
-
55
- if content.is_a?(Array)
56
- content.each { |c| builder.variant { c.to_xml builder } }
57
- else
58
- builder.parent["language"] = language.join(",") if language&.any?
59
- builder.parent["script"] = script.join(",") if script&.any?
60
- builder.text content.encode(xml: :text)
61
- end
62
- end
63
-
64
- # @return [Hash]
65
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
66
- if content.is_a? String
67
- return content unless language || script
68
-
69
- hash = { "content" => content }
70
- hash["language"] = single_element_array(language) if language&.any?
71
- hash["script"] = single_element_array(script) if script&.any?
72
- hash
73
- else content.map &:to_hash
74
- end
75
- end
76
-
77
- # @param prefix [String]
78
- # @param count [Integer] number of elements
79
- # @return [String]
80
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
81
- pref = prefix.empty? ? prefix : prefix + "."
82
- if content.is_a? String
83
- out = count > 1 ? "#{prefix}::\n" : ""
84
- out += "#{pref}content:: #{content}\n"
85
- language&.each { |l| out += "#{pref}language:: #{l}\n" }
86
- script&.each { |s| out += "#{pref}script:: #{s}\n" }
87
- out
88
- else
89
- content.map { |c| c.to_asciibib "#{pref}variant", content.size }.join
90
- end
91
- end
92
- end
93
- end
@@ -1,44 +0,0 @@
1
- module RelatonBib
2
- class Medium
3
- # @return [String, NilClass]
4
- attr_reader :form, :size, :scale
5
-
6
- # @param form [String, NilClass]
7
- # @param size [String, NilClass]
8
- # @param scale [String, NilClass]
9
- def initialize(form: nil, size: nil, scale: nil)
10
- @form = form
11
- @size = size
12
- @scale = scale
13
- end
14
-
15
- # @param builder [Nokogiri::XML::Builder]
16
- def to_xml(builder)
17
- builder.medium do
18
- builder.form form if form
19
- builder.size size if size
20
- builder.scale scale if scale
21
- end
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
32
-
33
- # @param prefix [String]
34
- # @return [String]
35
- def to_asciibib(prefix = "")
36
- pref = prefix.empty? ? "medium." : prefix + ".medium."
37
- out = ""
38
- out += "#{pref}form:: #{form}\n" if form
39
- out += "#{pref}size:: #{size}\n" if size
40
- out += "#{pref}scale:: #{scale}\n" if scale
41
- out
42
- end
43
- end
44
- end
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "relaton_bib/contributor"
4
-
5
- module RelatonBib
6
- # Organization identifier.
7
- class OrgIdentifier
8
- ORCID = "orcid"
9
- URI = "uri"
10
-
11
- # @return [String]
12
- attr_reader :type
13
-
14
- # @return [String]
15
- attr_reader :value
16
-
17
- # @param type [String] "orcid" or "uri"
18
- # @param value [String]
19
- def initialize(type, value)
20
- unless [ORCID, URI].include? type
21
- raise ArgumentError, 'Invalid type. It should be "orsid" or "uri".'
22
- end
23
-
24
- @type = type
25
- @value = value
26
- end
27
-
28
- # @param builder [Nokogiri::XML::Builder]
29
- def to_xml(builder)
30
- builder.identifier(value, type: type)
31
- end
32
-
33
- # @return [Hash]
34
- def to_hash
35
- { "type" => type, "id" => value }
36
- end
37
-
38
- # @param prefix [String]
39
- # @param count [Integer]
40
- # @return [String]
41
- def to_asciibib(prefix = "", count = 1)
42
- pref = prefix.empty? ? prefix : prefix + "."
43
- out = count > 1 ? "#{pref}identifier::\m" : ""
44
- out += "#{pref}identifier.type:: #{type}\n"
45
- out += "#{pref}identifier.value:: #{value}\n"
46
- out
47
- end
48
- end
49
-
50
- # Organization.
51
- class Organization < Contributor
52
- # @return [Array<RelatonBib::LocalizedString>]
53
- attr_reader :name
54
-
55
- # @return [RelatonBib::LocalizedString, NilClass]
56
- attr_reader :abbreviation
57
-
58
- # @return [RelatonBib::LocalizedString, NilClass]
59
- attr_reader :subdivision
60
-
61
- # @return [Array<RelatonBib::OrgIdentifier>]
62
- attr_reader :identifier
63
-
64
- # @param name [String, Hash, Array<String, Hash>]
65
- # @param abbreviation [RelatoBib::LocalizedString, String]
66
- # @param subdivision [RelatoBib::LocalizedString, String]
67
- # @param url [String]
68
- # @param identifier [Array<RelatonBib::OrgIdentifier>]
69
- # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
70
- def initialize(**args) # rubocop:disable Metrics/AbcSize
71
- raise ArgumentError, "missing keyword: name" unless args[:name]
72
-
73
- super(url: args[:url], contact: args.fetch(:contact, []))
74
-
75
- @name = if args[:name].is_a?(Array)
76
- args[:name].map { |n| localized_string(n) }
77
- else
78
- [localized_string(args[:name])]
79
- end
80
-
81
- @abbreviation = localized_string args[:abbreviation]
82
- @subdivision = localized_string args[:subdivision]
83
- @identifier = args.fetch(:identifier, [])
84
- end
85
-
86
- # @param builder [Nokogiri::XML::Builder]
87
- def to_xml(builder) # rubocop:disable Metrics/AbcSize
88
- builder.organization do
89
- name.each do |n|
90
- builder.name { |b| n.to_xml b }
91
- end
92
- builder.subdivision { |s| subdivision.to_xml s } if subdivision
93
- builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation
94
- builder.uri url if uri
95
- identifier.each { |identifier| identifier.to_xml builder }
96
- super
97
- end
98
- end
99
-
100
- # @return [Hash]
101
- def to_hash
102
- hash = { "name" => single_element_array(name) }
103
- hash["abbreviation"] = abbreviation.to_hash if abbreviation
104
- hash["identifier"] = single_element_array(identifier) if identifier&.any?
105
- hash["subdivision"] = subdivision.to_hash if subdivision
106
- { "organization" => hash.merge(super) }
107
- end
108
-
109
- # @param prefix [String]
110
- # @param count [Integer]
111
- # @return [String]
112
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
113
- pref = prefix.sub /\*$/, "organization"
114
- out = count > 1 ? "#{pref}::\m" : ""
115
- name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
116
- out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
117
- out += subdivision.to_asciibib "#{pref}.subdivision" if subdivision
118
- identifier.each { |n| out += n.to_asciibib pref, identifier.size }
119
- out += super pref
120
- out
121
- end
122
-
123
- private
124
-
125
- # @param arg [String, Hash, RelatoBib::LocalizedString]
126
- # @return [RelatoBib::LocalizedString]
127
- def localized_string(arg)
128
- if arg.is_a?(String) then LocalizedString.new(arg)
129
- elsif arg.is_a?(Hash)
130
- LocalizedString.new(arg[:content], arg[:language], arg[:script])
131
- elsif arg.is_a? LocalizedString then arg
132
- end
133
- end
134
- end
135
- end
@@ -1,206 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "relaton_bib/contributor"
4
-
5
- module RelatonBib
6
- # Person's full name
7
- class FullName
8
- include RelatonBib
9
-
10
- # @return [Array<RelatonBib::LocalizedString>]
11
- attr_accessor :forename
12
-
13
- # @return [Array<RelatonBib::LocalizedString>]
14
- attr_accessor :initial
15
-
16
- # @return [RelatonBib::LocalizedString]
17
- attr_accessor :surname
18
-
19
- # @return [Array<RelatonBib::LocalizedString>]
20
- attr_accessor :addition
21
-
22
- # @return [Array<RelatonBib::LocalizedString>]
23
- attr_accessor :prefix
24
-
25
- # @return [RelatonBib::LocalizedString]
26
- attr_reader :completename
27
-
28
- # @param surname [RelatonBib::LocalizedString]
29
- # @param forename [Array<RelatonBib::LocalizedString>]
30
- # @param initial [Array<RelatonBib::LocalizedString>]
31
- # @param addition [Array<RelatonBib::LocalizedString>]
32
- # @param prefix [Array<RelatonBib::LocalizedString>]
33
- # @param completename [RelatonBib::LocalizedString]
34
- def initialize(**args)
35
- unless args[:surname] || args[:completename]
36
- raise ArgumentError, "Should be given :surname or :completename"
37
- end
38
-
39
- @surname = args[:surname]
40
- @forename = args.fetch :forename, []
41
- @initial = args.fetch :initial, []
42
- @addition = args.fetch :addition, []
43
- @prefix = args.fetch :prefix, []
44
- @completename = args[:completename]
45
- end
46
-
47
- # @param builder [Nokogiri::XML::Builder]
48
- def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
49
- builder.name do
50
- if completename
51
- builder.completename { completename.to_xml builder }
52
- else
53
- prefix.each { |p| builder.prefix { p.to_xml builder } }
54
- forename.each { |f| builder.forename { f.to_xml builder } }
55
- initial.each { |i| builder.initial { i.to_xml builder } }
56
- builder.surname { surname.to_xml builder }
57
- addition.each { |a| builder.addition { a.to_xml builder } }
58
- end
59
- end
60
- end
61
-
62
- # @return [Hash]
63
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
64
- hash = {}
65
- hash["forename"] = single_element_array(forename) if forename&.any?
66
- hash["initial"] = single_element_array(initial) if initial&.any?
67
- hash["surname"] = surname.to_hash if surname
68
- hash["addition"] = single_element_array(addition) if addition&.any?
69
- hash["prefix"] = single_element_array(prefix) if prefix&.any?
70
- hash["completename"] = completename.to_hash if completename
71
- hash
72
- end
73
-
74
- # @param pref [String]
75
- # @return [String]
76
- def to_asciibib(pref) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
77
- prf = pref.empty? ? pref : pref + "."
78
- prf += "name."
79
- out = forename.map do |fn|
80
- fn.to_asciibib "#{prf}forename", forename.size
81
- end.join
82
- initial.each { |i| out += i.to_asciibib "#{prf}initial", initial.size }
83
- out += surname.to_asciibib "#{prf}surname" if surname
84
- addition.each do |ad|
85
- out += ad.to_asciibib "#{prf}addition", addition.size
86
- end
87
- prefix.each { |pr| out += pr.to_asciibib "#{prf}prefix", prefix.size }
88
- out += completename.to_asciibib "#{prf}completename" if completename
89
- out
90
- end
91
- end
92
-
93
- # Person identifier type.
94
- module PersonIdentifierType
95
- ISNI = "isni"
96
- URI = "uri"
97
-
98
- # Checks type.
99
- # @param type [String]
100
- # @raise [ArgumentError] if type isn't "isni" or "uri"
101
- def self.check(type)
102
- unless [ISNI, URI].include? type
103
- raise ArgumentError, 'Invalid type. It should be "isni" or "uri".'
104
- end
105
- end
106
- end
107
-
108
- # Person identifier.
109
- class PersonIdentifier
110
- # @return [RelatonBib::PersonIdentifierType::ISNI,
111
- # RelatonBib::PersonIdentifierType::URI]
112
- attr_accessor :type
113
-
114
- # @return [String]
115
- attr_accessor :value
116
-
117
- # @param type [RelatonBib::PersonIdentifierType::ISNI,
118
- # RelatonBib::PersonIdentifierType::URI]
119
- # @param value [String]
120
- def initialize(type, value)
121
- PersonIdentifierType.check type
122
-
123
- @type = type
124
- @value = value
125
- end
126
-
127
- # @param builser [Nokogiri::XML::Builder]
128
- def to_xml(builder)
129
- builder.identifier value, type: type
130
- end
131
-
132
- # @return [Hash]
133
- def to_hash
134
- { "type" => type, "id" => value }
135
- end
136
-
137
- # @param prefix [String]
138
- # @param count [Integer] number of ids
139
- # @return [String]
140
- def to_asciibib(prefix = "", count = 1)
141
- pref = prefix.empty? ? prefix : prefix + "."
142
- out = count > 1 ? "#{prefix}::\n" : ""
143
- out += "#{pref}type:: #{type}\n"
144
- out += "#{pref}value:: #{value}\n"
145
- out
146
- end
147
- end
148
-
149
- # Person class.
150
- class Person < Contributor
151
- # @return [RelatonBib::FullName]
152
- attr_accessor :name
153
-
154
- # @return [Array<RelatonBib::Affiliation>]
155
- attr_accessor :affiliation
156
-
157
- # @return [Array<RelatonBib::PersonIdentifier>]
158
- attr_accessor :identifier
159
-
160
- # @param name [RelatonBib::FullName]
161
- # @param affiliation [Array<RelatonBib::Affiliation>]
162
- # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
163
- # @param identifier [Array<RelatonBib::PersonIdentifier>]
164
- # @param url [String, NilClass]
165
- def initialize(name:, affiliation: [], contact: [], identifier: [],
166
- url: nil)
167
- super(contact: contact, url: url)
168
- @name = name
169
- @affiliation = affiliation
170
- @identifier = identifier
171
- end
172
-
173
- # @param builder [Nokogiri::XML::Builder]
174
- def to_xml(builder)
175
- builder.person do
176
- name.to_xml builder
177
- affiliation.each { |a| a.to_xml builder }
178
- identifier.each { |id| id.to_xml builder }
179
- contact.each { |contact| contact.to_xml builder }
180
- end
181
- end
182
-
183
- # @return [Hash]
184
- def to_hash
185
- hash = { "name" => name.to_hash }
186
- if affiliation&.any?
187
- hash["affiliation"] = single_element_array(affiliation)
188
- end
189
- hash["identifier"] = single_element_array(identifier) if identifier&.any?
190
- { "person" => hash.merge(super) }
191
- end
192
-
193
- # @param prefix [String]
194
- # @count [Integer] number of persons
195
- # @return [String]
196
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
197
- pref = prefix.sub /\*$/, "person"
198
- out = count > 1 ? "#{pref}::\n" : ""
199
- out += name.to_asciibib pref
200
- affiliation.each { |af| out += af.to_asciibib pref, affiliation.size }
201
- identifier.each { |id| out += id.to_asciibib pref, identifier.size }
202
- out += super pref
203
- out
204
- end
205
- end
206
- end
@@ -1,49 +0,0 @@
1
- module RelatonBib
2
- class Place
3
- # @return [String]
4
- attr_reader :name
5
-
6
- # @return [String, NilClass]
7
- attr_reader :uri, :region
8
-
9
- # @param name [String]
10
- # @param uri [String, NilClass]
11
- # @param region [String, NilClass]
12
- def initialize(name:, uri: nil, region: nil)
13
- @name = name
14
- @uri = uri
15
- @region = region
16
- end
17
-
18
- # @param builder [Nologiri::XML::Builder]
19
- def to_xml(builder)
20
- xml = builder.place name
21
- xml[:uri] = uri if uri
22
- xml[:region] = region if region
23
- end
24
-
25
- # @return [Hash]
26
- def to_hash
27
- if uri || region
28
- hash = { name: name }
29
- hash["uri"] = uri if uri
30
- hash["region"] = region if region
31
- hash
32
- else
33
- name
34
- end
35
- end
36
-
37
- # @param prefix [String]
38
- # @param count [Integer] number of places
39
- # @return [Stirng]
40
- def to_asciibib(prefix = "", count = 1)
41
- pref = prefix.empty? ? "place" : prefix + ".place"
42
- out = count > 1 ? "#{pref}::\n" : ""
43
- out += "#{pref}.name:: #{name}\n"
44
- out += "#{pref}.uri:: #{uri}\n" if uri
45
- out += "#{pref}.region:: #{region}\n" if region
46
- out
47
- end
48
- end
49
- end
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RelatonBib
4
- #
5
- # Series class.
6
- #
7
- class Series
8
- TYPES = %w[main alt].freeze
9
-
10
- # @return [String, NilClass] allowed values: "main" or "alt"
11
- attr_reader :type
12
-
13
- # @return [RelatonBib::FormattedRef, NilClass]
14
- attr_reader :formattedref
15
-
16
- # @return [RelatonBib::FormattedString, NilClass] title
17
- attr_reader :title
18
-
19
- # @return [String, NilClass]
20
- attr_reader :place
21
-
22
- # @return [String, NilClass]
23
- attr_reader :organization
24
-
25
- # @return [RelatonBib::LocalizedString, NilClass]
26
- attr_reader :abbreviation
27
-
28
- # @return [String, NilClass] date or year
29
- attr_reader :from
30
-
31
- # @return [String, NilClass] date or year
32
- attr_reader :to
33
-
34
- # @return [String, NilClass]
35
- attr_reader :number
36
-
37
- # @return [String, NilClass]
38
- attr_reader :partnumber
39
-
40
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
-
42
- # @param type [String, NilClass] title or formattedref argument should be
43
- # passed
44
- # @param formattedref [RelatonBib::FormattedRef, NilClass]
45
- # @param title [RelatonBib::TypedTitleString, NilClass]
46
- # @param place [String, NilClass]
47
- # @param orgaization [String, NilClass]
48
- # @param abbreviation [RelatonBib::LocalizedString, NilClass]
49
- # @param from [String, NilClass]
50
- # @param to [String, NilClass]
51
- # @param number [String, NilClass]
52
- # @param partnumber [String, NilClass]
53
- def initialize(**args)
54
- unless args[:title].is_a?(RelatonBib::TypedTitleString) ||
55
- args[:formattedref]
56
- raise ArgumentError, "argument `title` or `formattedref` should present"
57
- end
58
-
59
- if args[:type] && !TYPES.include?(args[:type])
60
- warn "[relaton-bib] Series type is invalid: #{args[:type]}"
61
- end
62
-
63
- @type = args[:type] # if %w[main alt].include? args[:type]
64
- @title = args[:title]
65
- @formattedref = args[:formattedref]
66
- @place = args[:place]
67
- @organization = args[:organization]
68
- @abbreviation = args[:abbreviation]
69
- @from = args[:from]
70
- @to = args[:to]
71
- @number = args[:number]
72
- @partnumber = args[:partnumber]
73
- end
74
- # rubocop:enable Metrics/MethodLength
75
-
76
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
77
-
78
- # @param builder [Nokogiri::XML::Builder]
79
- def to_xml(builder) # rubocop:disable Metrics/MethodLength
80
- xml = builder.series do
81
- if formattedref
82
- formattedref.to_xml builder
83
- else
84
- builder.title { title.to_xml builder }
85
- builder.place place if place
86
- builder.organization organization if organization
87
- builder.abbreviation { abbreviation.to_xml builder } if abbreviation
88
- builder.from from if from
89
- builder.to to if to
90
- builder.number number if number
91
- builder.partnumber partnumber if partnumber
92
- end
93
- end
94
- xml[:type] = type if type
95
- end
96
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
97
- # rubocop:enable Metrics/PerceivedComplexity
98
-
99
- # @return [Hash]
100
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
101
- hash = {}
102
- hash["type"] = type if type
103
- hash["formattedref"] = formattedref.to_hash if formattedref
104
- hash["title"] = title.to_hash if title
105
- hash["place"] = place if place
106
- hash["organization"] = organization if organization
107
- hash["abbreviation"] = abbreviation.to_hash if abbreviation
108
- hash["from"] = from if from
109
- hash["to"] = to if to
110
- hash["number"] = number if number
111
- hash["partnumber"] = partnumber if partnumber
112
- hash
113
- end
114
-
115
- # @param prefix [String]
116
- # @param count [Integer]
117
- # @return [String]
118
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
119
- pref = prefix.empty? ? "series" : prefix + ".series"
120
- out = count > 1 ? "#{pref}::\n" : ""
121
- out += "#{pref}.type:: #{type}\n" if type
122
- out += formattedref.to_asciibib pref if formattedref
123
- out += title.to_asciibib pref if title
124
- out += "#{pref}.place:: #{place}\n" if place
125
- out += "#{pref}.organization:: #{organization}\n" if organization
126
- out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
127
- out += "#{pref}.from:: #{from}\n" if from
128
- out += "#{pref}.to:: #{to}\n" if to
129
- out += "#{pref}.number:: #{number}\n" if number
130
- out += "#{pref}.partnumber:: #{partnumber}\n" if partnumber
131
- out
132
- end
133
- end
134
- end