relaton-bib 1.20.7 → 2.0.0.pre.alpha.1

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 (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/README.adoc +183 -154
  4. data/bin/console +1 -1
  5. data/grammars/basicdoc.rng +1516 -645
  6. data/grammars/biblio-standoc.rng +100 -20
  7. data/grammars/biblio.rng +959 -356
  8. data/grammars/versions.json +10 -10
  9. data/lib/relaton/bib/hash_parser_v1.rb +711 -0
  10. data/lib/relaton/bib/item_data.rb +168 -0
  11. data/lib/relaton/bib/model/address.rb +22 -0
  12. data/lib/relaton/bib/model/affiliation.rb +16 -0
  13. data/lib/relaton/bib/model/bibdata.rb +24 -0
  14. data/lib/relaton/bib/model/bibitem.rb +23 -0
  15. data/lib/relaton/bib/model/contact.rb +18 -0
  16. data/lib/relaton/bib/model/contribution_info.rb +16 -0
  17. data/lib/relaton/bib/model/contributor.rb +71 -0
  18. data/lib/relaton/bib/model/copyright.rb +27 -0
  19. data/lib/relaton/bib/model/date.rb +29 -0
  20. data/lib/relaton/bib/model/depiction.rb +14 -0
  21. data/lib/relaton/bib/model/docidentifier.rb +33 -0
  22. data/lib/relaton/bib/model/doctype.rb +14 -0
  23. data/lib/relaton/bib/model/edition.rb +14 -0
  24. data/lib/relaton/bib/model/editorial_group.rb +14 -0
  25. data/lib/relaton/bib/model/ext.rb +29 -0
  26. data/lib/relaton/bib/model/extent.rb +16 -0
  27. data/lib/relaton/bib/model/full_name_type.rb +64 -0
  28. data/lib/relaton/bib/model/fullname.rb +11 -0
  29. data/lib/relaton/bib/model/ics.rb +14 -0
  30. data/lib/relaton/bib/model/image.rb +28 -0
  31. data/lib/relaton/bib/model/item.rb +129 -0
  32. data/lib/relaton/bib/model/item_base.rb +19 -0
  33. data/lib/relaton/bib/model/keyword.rb +30 -0
  34. data/lib/relaton/bib/model/locality.rb +18 -0
  35. data/lib/relaton/bib/model/locality_stack.rb +14 -0
  36. data/lib/relaton/bib/model/localized_string.rb +57 -0
  37. data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
  38. data/lib/relaton/bib/model/logo.rb +12 -0
  39. data/lib/relaton/bib/model/medium.rb +22 -0
  40. data/lib/relaton/bib/model/note.rb +16 -0
  41. data/lib/relaton/bib/model/organization.rb +13 -0
  42. data/lib/relaton/bib/model/organization_type.rb +42 -0
  43. data/lib/relaton/bib/model/person.rb +36 -0
  44. data/lib/relaton/bib/model/phone.rb +14 -0
  45. data/lib/relaton/bib/model/place.rb +33 -0
  46. data/lib/relaton/bib/model/price.rb +14 -0
  47. data/lib/relaton/bib/model/relation.rb +43 -0
  48. data/lib/relaton/bib/model/series.rb +32 -0
  49. data/lib/relaton/bib/model/size.rb +23 -0
  50. data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
  51. data/lib/relaton/bib/model/status.rb +27 -0
  52. data/lib/relaton/bib/model/structured_identifier.rb +48 -0
  53. data/lib/relaton/bib/model/subdivision.rb +14 -0
  54. data/lib/relaton/bib/model/technical_committee.rb +14 -0
  55. data/lib/relaton/bib/model/title.rb +18 -0
  56. data/lib/relaton/bib/model/uri.rb +18 -0
  57. data/lib/relaton/bib/model/validity.rb +16 -0
  58. data/lib/relaton/bib/model/version.rb +14 -0
  59. data/lib/relaton/bib/model/workgroup.rb +20 -0
  60. data/lib/relaton/bib/parser/rfc_address.rb +60 -0
  61. data/lib/relaton/bib/parser/rfc_contacts.rb +35 -0
  62. data/lib/relaton/bib/parser/rfc_docidentifier.rb +70 -0
  63. data/lib/relaton/bib/parser/rfc_organization.rb +31 -0
  64. data/lib/relaton/bib/parser/rfc_person.rb +42 -0
  65. data/lib/relaton/bib/parser/rfc_reference.rb +143 -0
  66. data/lib/relaton/bib/parser/rfc_referencegroup.rb +45 -0
  67. data/lib/relaton/bib/parser/rfc_shared.rb +23 -0
  68. data/lib/relaton/bib/renderer/bibtex_builder.rb +348 -0
  69. data/lib/relaton/bib/renderer/rfc.rb +297 -0
  70. data/lib/relaton/bib/util.rb +18 -0
  71. data/lib/relaton/bib/version.rb +5 -0
  72. data/lib/{relaton_bib.rb → relaton/bib.rb} +47 -36
  73. data/lib/{relaton_bib → relaton}/bibtex_parser.rb +24 -27
  74. data/lib/{relaton_bib → relaton}/bibxml_parser.rb +43 -46
  75. data/lib/{relaton_bib → relaton}/hit.rb +3 -3
  76. data/lib/{relaton_bib → relaton}/hit_collection.rb +2 -2
  77. data/lib/{relaton_bib → relaton}/workers_pool.rb +1 -1
  78. data/lib/{relaton_bib → relaton}/xml_parser.rb +49 -51
  79. data/relaton-bib.gemspec +8 -8
  80. metadata +95 -74
  81. data/lib/relaton_bib/bib_item_locality.rb +0 -175
  82. data/lib/relaton_bib/biblio_note.rb +0 -72
  83. data/lib/relaton_bib/biblio_version.rb +0 -46
  84. data/lib/relaton_bib/bibliographic_date.rb +0 -119
  85. data/lib/relaton_bib/bibliographic_item.rb +0 -668
  86. data/lib/relaton_bib/bibliographic_size.rb +0 -103
  87. data/lib/relaton_bib/classification.rb +0 -40
  88. data/lib/relaton_bib/config.rb +0 -16
  89. data/lib/relaton_bib/contribution_info.rb +0 -117
  90. data/lib/relaton_bib/contributor.rb +0 -277
  91. data/lib/relaton_bib/copyright_association.rb +0 -79
  92. data/lib/relaton_bib/document_identifier.rb +0 -118
  93. data/lib/relaton_bib/document_relation.rb +0 -95
  94. data/lib/relaton_bib/document_relation_collection.rb +0 -57
  95. data/lib/relaton_bib/document_status.rb +0 -92
  96. data/lib/relaton_bib/document_type.rb +0 -52
  97. data/lib/relaton_bib/edition.rb +0 -55
  98. data/lib/relaton_bib/editorial_group.rb +0 -41
  99. data/lib/relaton_bib/extent.rb +0 -39
  100. data/lib/relaton_bib/forename.rb +0 -65
  101. data/lib/relaton_bib/formatted_ref.rb +0 -17
  102. data/lib/relaton_bib/formatted_string.rb +0 -133
  103. data/lib/relaton_bib/full_name.rb +0 -108
  104. data/lib/relaton_bib/hash_converter.rb +0 -568
  105. data/lib/relaton_bib/ics.rb +0 -42
  106. data/lib/relaton_bib/image.rb +0 -95
  107. data/lib/relaton_bib/localized_string.rb +0 -149
  108. data/lib/relaton_bib/medium.rb +0 -76
  109. data/lib/relaton_bib/organization.rb +0 -165
  110. data/lib/relaton_bib/person.rb +0 -129
  111. data/lib/relaton_bib/place.rb +0 -203
  112. data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
  113. data/lib/relaton_bib/renderer/bibxml.rb +0 -296
  114. data/lib/relaton_bib/series.rb +0 -119
  115. data/lib/relaton_bib/structured_identifier.rb +0 -173
  116. data/lib/relaton_bib/technical_committee.rb +0 -34
  117. data/lib/relaton_bib/typed_title_string.rb +0 -191
  118. data/lib/relaton_bib/typed_uri.rb +0 -57
  119. data/lib/relaton_bib/util.rb +0 -16
  120. data/lib/relaton_bib/validity.rb +0 -52
  121. data/lib/relaton_bib/version.rb +0 -3
  122. data/lib/relaton_bib/workgroup.rb +0 -58
  123. /data/lib/{relaton_bib → relaton}/deep_dup.rb +0 -0
@@ -1,103 +0,0 @@
1
- module RelatonBib
2
- class BibliographicSize
3
- extend Forwardable
4
-
5
- def_delegators :@size, :any?
6
-
7
- # @return [Array<RelatonBib::BibliographicSize::Value>]
8
- attr_reader :size
9
-
10
- #
11
- # Initialize a BibliographicSize object.
12
- #
13
- # @param [<Type>] size <description>
14
- #
15
- def initialize(size)
16
- @size = size
17
- end
18
-
19
- #
20
- # Render BibliographicSize object to XML.
21
- #
22
- # @param [Nokogiri::XML::Builder] builder the XML builder
23
- #
24
- def to_xml(builder)
25
- return if size.empty?
26
-
27
- builder.size do
28
- size.each { |s| s.to_xml builder }
29
- end
30
- end
31
-
32
- #
33
- # Render BibliographicSize object to AsciiBib.
34
- #
35
- # @param [String] prefix prefix for the size
36
- #
37
- # @return [String] AsciiBib string
38
- #
39
- def to_asciibib(prefix = "")
40
- pref = prefix.empty? ? "size" : "#{prefix}.size"
41
- size.map { |s| s.to_asciibib pref, size.size }.join
42
- end
43
-
44
- #
45
- # Render BibliographicSize object to hash.
46
- #
47
- # @return [<Type>] <description>
48
- #
49
- def to_hash
50
- size.map &:to_hash
51
- end
52
-
53
- class Value
54
- # @return [String]
55
- attr_reader :type, :value
56
-
57
- #
58
- # Initialize a BibliographicSize::Value object.
59
- #
60
- # @param [String] type the type of the size
61
- # @param [String] value size value
62
- #
63
- def initialize(type:, value:)
64
- @type = type
65
- @value = value
66
- end
67
-
68
- #
69
- # Render BibliographicSize::Value object to XML.
70
- #
71
- # @param [Nokogiri::XML::Builder] builder the XML builder
72
- #
73
- def to_xml(builder)
74
- builder.value value, type: type
75
- end
76
-
77
- #
78
- # Render BibliographicSize::Value object to hash.
79
- #
80
- # @return [<Type>] <description>
81
- #
82
- def to_hash
83
- { type: type, value: value }
84
- end
85
-
86
- #
87
- # Render BibliographicSize::Value object to AsciiBib.
88
- #
89
- # @param [String] prefix prefix for the size
90
- # @param [Integer] size size of the array
91
- #
92
- # @return [String] AsciiBib string
93
- #
94
- def to_asciibib(prefix, size)
95
- pref = prefix.empty? ? "" : "#{prefix}."
96
- out = ""
97
- out << "#{prefix}::\n" if size.size > 1
98
- out << "#{pref}type:: #{type}\n"
99
- out << "#{pref}value:: #{value}\n"
100
- end
101
- end
102
- end
103
- end
@@ -1,40 +0,0 @@
1
- module RelatonBib
2
- class Classification
3
- # @return [String, nil]
4
- attr_reader :type
5
-
6
- # @return [String]
7
- attr_reader :value
8
-
9
- # @param type [String, nil]
10
- # @param value [String]
11
- def initialize(type: nil, value:)
12
- @type = type
13
- @value = value
14
- end
15
-
16
- # @param builder [Nokogiri::XML::Builder]
17
- def to_xml(builder)
18
- xml = builder.classification value
19
- xml[:type] = type if type
20
- end
21
-
22
- # @return [Hash]
23
- def to_hash
24
- hash = { "value" => value }
25
- hash["type"] = type if type
26
- hash
27
- end
28
-
29
- # @param prefix [String]
30
- # @param count [Integer] number of classifications
31
- # @return [String]
32
- def to_asciibib(prefix = "", count = 1)
33
- pref = prefix.empty? ? "classification" : prefix + ".classification"
34
- out = count > 1 ? "#{pref}::\n" : ""
35
- out += "#{pref}.type:: #{type}\n" if type
36
- out += "#{pref}.value:: #{value}\n"
37
- out
38
- end
39
- end
40
- end
@@ -1,16 +0,0 @@
1
- module RelatonBib
2
- module Config
3
- def configure
4
- yield configuration if block_given?
5
- end
6
-
7
- def configuration
8
- @configuration ||= self::Configuration.new
9
- end
10
- end
11
-
12
- class Configuration
13
- end
14
-
15
- extend Config
16
- end
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "relaton_bib/person"
4
-
5
- # RelatonBib module
6
- module RelatonBib
7
- # Contributor's role.
8
- class ContributorRole
9
- include RelatonBib
10
-
11
- TYPES = %w[author performer publisher editor adapter translator
12
- distributor realizer owner authorizer enabler subject].freeze
13
-
14
- # @return [Array<RelatonBib::FormattedString>]
15
- attr_reader :description
16
-
17
- # @return [Strig]
18
- attr_reader :type
19
-
20
- # @param type [String] allowed types "author", "editor",
21
- # "cartographer", "publisher"
22
- # @param description [Array<String>]
23
- def initialize(**args)
24
- if args[:type] && !TYPES.include?(args[:type])
25
- Util.warn %{Contributor's type `#{args[:type]}` is invalid.}
26
- end
27
-
28
- @type = args[:type]
29
- @description = (args[:description] || []).map do |d|
30
- FormattedString.new content: d, format: nil
31
- end
32
- end
33
-
34
- # @param opts [Hash]
35
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
36
- # @option opts [String] :lang language
37
- def to_xml(**opts) # rubocop:disable Metrics/AbcSize
38
- opts[:builder].role(type: type) do |builder|
39
- desc = description.select { |d| d.language&.include? opts[:lang] }
40
- desc = description unless desc.any?
41
- desc.each do |d|
42
- builder.description { |b| d.to_xml(b) }
43
- end
44
- end
45
- end
46
-
47
- # @return [Hash, String]
48
- def to_hash
49
- hash = {}
50
- hash["description"] = description.map(&:to_hash) if description&.any?
51
- hash["type"] = type if type
52
- hash
53
- end
54
-
55
- # @param prefix [String]
56
- # @param count [Integer] number of contributors
57
- # 2return [String]
58
- def to_asciibib(prefix = "", count = 1)
59
- pref = prefix.empty? ? prefix : "#{prefix}."
60
- out = count > 1 ? "#{prefix}.role::\n" : ""
61
- description.each do |d|
62
- out += d.to_asciibib "#{pref}role.description", description.size
63
- end
64
- out += "#{pref}role.type:: #{type}\n" if type
65
- out
66
- end
67
- end
68
-
69
- # Contribution info.
70
- class ContributionInfo
71
- include RelatonBib
72
-
73
- # @return [Array<RelatonBib::ContributorRole>]
74
- attr_reader :role
75
-
76
- # @return
77
- # [RelatonBib::Person, RelatonBib::Organization]
78
- attr_reader :entity
79
-
80
- # @param entity [RelatonBib::Person, RelatonBib::Organization]
81
- # @param role [Array<Hash>]
82
- # @option role [String] :type
83
- # @option role [Array<String>] :description
84
- def initialize(entity:, role: [])
85
- if role.empty?
86
- role << { type: entity.is_a?(Person) ? "author" : "publisher" }
87
- end
88
- @entity = entity
89
- @role = role.map { |r| ContributorRole.new(**r) }
90
- end
91
-
92
- # @param opts [Hash]
93
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
94
- # @option opts [String, Symbol] :lang language
95
- def to_xml(**opts)
96
- entity.to_xml(**opts)
97
- end
98
-
99
- # @return [Hash]
100
- def to_hash
101
- hash = entity.to_hash
102
- hash["role"] = single_element_array(role) if role&.any?
103
- hash
104
- end
105
-
106
- # @param prefix [String]
107
- # @param count [Integer] number of contributors
108
- # @return [String]
109
- def to_asciibib(prefix = "", count = 1)
110
- pref = prefix.split(".").first
111
- out = count > 1 ? "#{pref}::\n" : ""
112
- out += entity.to_asciibib prefix
113
- role.each { |r| out += r.to_asciibib pref, role.size }
114
- out
115
- end
116
- end
117
- end
@@ -1,277 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "uri"
4
-
5
- module RelatonBib
6
- # Address class.
7
- class Address
8
- # @return [Array<String>]
9
- attr_reader :street
10
-
11
- # @return [String, nil]
12
- attr_reader :city, :state, :country, :postcode, :formatted_address
13
-
14
- # @param street [Array<String>] streets
15
- # @param city [String, nil] city, should be present or formatted address provided
16
- # @param state [String, nil] state
17
- # @param country [String, nil] country, should be present or formatted address provided
18
- # @param postcode [String, nil] postcode
19
- # @param formatted_address [String, nil] formatted address, should be present or city and country provided
20
- def initialize(**args) # rubocop:disable Metrics/CyclomaticComplexity
21
- unless args[:formatted_address] || (args[:city] && args[:country])
22
- raise ArgumentError, "Either formatted address or city and country must be provided"
23
- end
24
-
25
- @street = args[:street] || []
26
- @city = args[:city]
27
- @state = args[:state]
28
- @country = args[:country]
29
- @postcode = args[:postcode]
30
- @formatted_address = args[:formatted_address] unless args[:city] && args[:country]
31
- end
32
-
33
- def ==(other)
34
- street == other.street && city == other.city && state == other.state &&
35
- country == other.country && postcode == other.postcode &&
36
- formatted_address == other.formatted_address
37
- end
38
-
39
- # @param doc [Nokogiri::XML::Document]
40
- def to_xml(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
- doc.address do
42
- if formatted_address
43
- doc.formattedAddress formatted_address
44
- else
45
- street.each { |str| doc.street str }
46
- doc.city city
47
- doc.state state if state
48
- doc.country country
49
- doc.postcode postcode if postcode
50
- end
51
- end
52
- end
53
-
54
- # @return [Hash]
55
- def to_hash # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
56
- hash = { "address" => {} }
57
- if formatted_address
58
- hash["address"]["formatted_address"] = formatted_address
59
- else
60
- hash["address"]["street"] = street if street.any?
61
- hash["address"]["city"] = city
62
- hash["address"]["state"] = state if state
63
- hash["address"]["country"] = country
64
- hash["address"]["postcode"] = postcode if postcode
65
- end
66
- hash
67
- end
68
-
69
- # @param prefix [String]
70
- # @param count [Integer] number of addresses
71
- # @return [String]
72
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
73
- pref = prefix.empty? ? "address" : "#{prefix}.address"
74
- if formatted_address
75
- "#{pref}.formatted_address:: #{formatted_address}\n"
76
- else
77
- out = count > 1 ? "#{pref}::\n" : ""
78
- street.each { |st| out += "#{pref}.street:: #{st}\n" }
79
- out += "#{pref}.city:: #{city}\n"
80
- out += "#{pref}.state:: #{state}\n" if state
81
- out += "#{pref}.country:: #{country}\n"
82
- out += "#{pref}.postcode:: #{postcode}\n" if postcode
83
- out
84
- end
85
- end
86
- end
87
-
88
- # Contact class.
89
- class Contact
90
- # @return [String] allowed "phone", "email" or "uri"
91
- attr_reader :type
92
-
93
- # @return [String, nil]
94
- attr_reader :subtype
95
-
96
- # @return [String]
97
- attr_reader :value
98
-
99
- # @param type [String] allowed "phone", "email" or "uri"
100
- # @param subtype [String, nil] i.e. "fax", "mobile", "landline" for "phone"
101
- # or "work", "personal" for "uri" type
102
- # @param value [String]
103
- def initialize(type:, value:, subtype: nil)
104
- @type = type
105
- @subtype = subtype
106
- @value = value
107
- end
108
-
109
- def ==(other)
110
- type == other.type && subtype == other.subtype && value == other.value
111
- end
112
-
113
- # @param builder [Nokogiri::XML::Document]
114
- def to_xml(builder)
115
- node = builder.send type, value
116
- node["type"] = subtype if subtype
117
- end
118
-
119
- # @return [Hash]
120
- def to_hash
121
- hash = { type => value }
122
- hash["type"] = subtype if subtype
123
- hash
124
- end
125
-
126
- # @param prefix [String]
127
- # @param count [Integer] number of contacts
128
- # @return [string]
129
- def to_asciibib(prefix = "", count = 1)
130
- pref = prefix.empty? ? prefix : "#{prefix}."
131
- out = count > 1 ? "#{pref}contact::\n" : ""
132
- out += "#{pref}contact.#{type}:: #{value}\n"
133
- out += "#{pref}contact.type:: #{subtype}\n" if subtype
134
- out
135
- end
136
- end
137
-
138
- # Affiliation.
139
- class Affiliation
140
- include RelatonBib
141
-
142
- # @return [RelatonBib::LocalizedString, nil]
143
- attr_reader :name
144
-
145
- # @return [RelatonBib::Organization]
146
- attr_reader :organization
147
-
148
- # @param organization [RelatonBib::Organization, nil]
149
- # @param name [RelatonBib::LocalizedString, nil]
150
- # @param description [Array<RelatonBib::FormattedString>]
151
- def initialize(organization: nil, name: nil, description: [])
152
- @name = name
153
- @organization = organization
154
- @description = description
155
- end
156
-
157
- def ==(other)
158
- name == other.name && organization == other.organization && description == other.description
159
- end
160
-
161
- # @param opts [Hash]
162
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
163
- # @option opts [String] :lang language
164
- def to_xml(**opts)
165
- return unless organization || name || description&.any?
166
-
167
- opts[:builder].affiliation do |builder|
168
- name_xml builder
169
- description_xml builder
170
- organization&.to_xml(**opts)
171
- end
172
- end
173
-
174
- def name_xml(builder)
175
- builder.name { name.to_xml builder } if name
176
- end
177
-
178
- def description_xml(builder)
179
- description.each { |d| builder.description { d.to_xml builder } }
180
- end
181
-
182
- #
183
- # Get description.
184
- #
185
- # @param [String, nil] lang language if nil return all description
186
- #
187
- # @return return [Array<RelatonBib::FormattedString>] description
188
- #
189
- def description(lang = nil)
190
- return @description unless lang
191
-
192
- @description.select { |d| d.language&.include? lang }
193
- end
194
-
195
- #
196
- # Render affiliation as hash.
197
- #
198
- # @return [Hash]
199
- #
200
- def to_hash
201
- hash = organization&.to_hash || {}
202
- hash["name"] = name.to_hash if name
203
- if description&.any?
204
- hash["description"] = single_element_array(description)
205
- end
206
- hash
207
- end
208
-
209
- # @param prefix [String]
210
- # @param count [Integer]
211
- # @return [String]
212
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
213
- pref = prefix.empty? ? prefix : "#{prefix}."
214
- out = count > 1 ? "#{pref}affiliation::\n" : ""
215
- out += name.to_asciibib "#{pref}affiliation.name" if name
216
- description.each do |d|
217
- out += d.to_asciibib "#{pref}affiliation.description", description.size
218
- end
219
- out += organization.to_asciibib "#{pref}affiliation.*" if organization
220
- out
221
- end
222
- end
223
-
224
- # Contributor.
225
- class Contributor
226
- include RelatonBib
227
-
228
- # @return [URI]
229
- attr_reader :uri
230
-
231
- # @return [Array<RelatonBib::Address, RelatonBib::Contact>]
232
- attr_reader :contact
233
-
234
- # @param url [String, nil]
235
- # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
236
- def initialize(url: nil, contact: [])
237
- @uri = URI url if url
238
- @contact = contact
239
- end
240
-
241
- def ==(other)
242
- uri == other.uri && contact == other.contact
243
- end
244
-
245
- # Returns url.
246
- # @return [String]
247
- def url
248
- @uri.to_s
249
- end
250
-
251
- # @params builder [Nokogiri::XML::Builder]
252
- def to_xml(builder)
253
- contact.each { |contact| contact.to_xml builder }
254
- end
255
-
256
- # @return [Hash]
257
- def to_hash
258
- hash = {}
259
- hash["url"] = uri.to_s if uri
260
- hash["contact"] = single_element_array(contact) if contact&.any?
261
- hash
262
- end
263
-
264
- # @param prefix [String]
265
- # @return [String]
266
- def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
267
- pref = prefix.empty? ? prefix : "#{prefix}."
268
- out = ""
269
- out += "#{pref}url:: #{uri}\n" if uri
270
- addr = contact.select { |c| c.is_a? RelatonBib::Address }
271
- addr.each { |ct| out += ct.to_asciibib prefix, addr.size }
272
- cont = contact.select { |c| c.is_a? RelatonBib::Contact }
273
- cont.each { |ct| out += ct.to_asciibib prefix, cont.size }
274
- out
275
- end
276
- end
277
- end
@@ -1,79 +0,0 @@
1
- module RelatonBib
2
- # Copyright association.
3
- class CopyrightAssociation
4
- include RelatonBib
5
-
6
- # @return [Date]
7
- attr_reader :from
8
-
9
- # @return [Date, nil]
10
- attr_reader :to
11
-
12
- # @return [String, nil]
13
- attr_reader :scope
14
-
15
- # @return [Array<RelatonBib::ContributionInfo>]
16
- attr_reader :owner
17
-
18
- # rubocop:disable Metrics/AbcSize
19
-
20
- # @param owner [Array<Hash, RelatonBib::ContributionInfo>] contributor
21
- # @option owner [String] :name
22
- # @option owner [String] :abbreviation
23
- # @option owner [String] :url
24
- # @param from [String] date
25
- # @param to [String, nil] date
26
- # @param scope [String, nil]
27
- def initialize(owner:, from:, to: nil, scope: nil)
28
- unless owner.any?
29
- raise ArgumentError, "at least one owner should exist."
30
- end
31
-
32
- @owner = owner.map do |o|
33
- o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(**o)) : o
34
- end
35
-
36
- @from = Date.strptime(from.to_s, "%Y") if from.to_s.match?(/\d{4}/)
37
- @to = Date.strptime(to.to_s, "%Y") unless to.to_s.empty?
38
- @scope = scope
39
- end
40
-
41
- # @param opts [Hash]
42
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
43
- # @option opts [String, Symbol] :lang language
44
- def to_xml(**opts)
45
- opts[:builder].copyright do |builder|
46
- builder.from from ? from.year : "unknown"
47
- builder.to to.year if to
48
- owner.each { |o| builder.owner { o.to_xml(**opts) } }
49
- builder.scope scope if scope
50
- end
51
- end
52
- # rubocop:enable Metrics/AbcSize
53
-
54
- # @return [Hash]
55
- def to_hash # rubocop:disable Metrics/AbcSize
56
- owners = single_element_array(owner.map { |o| o.to_hash["organization"] })
57
- hash = {
58
- "owner" => owners,
59
- "from" => from.year.to_s,
60
- }
61
- hash["to"] = to.year.to_s if to
62
- hash["scope"] = scope if scope
63
- hash
64
- end
65
-
66
- # @param prefix [String]
67
- # @param count [Iteger] number of copyright elements
68
- # @return [String]
69
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
70
- pref = prefix.empty? ? "copyright" : "#{prefix}.copyright"
71
- out = count > 1 ? "#{pref}::\n" : ""
72
- owner.each { |ow| out += ow.to_asciibib "#{pref}.owner", owner.size }
73
- out += "#{pref}.from:: #{from.year}\n" if from
74
- out += "#{pref}.to:: #{to.year}\n" if to
75
- out += "#{pref}.scope:: #{scope}\n" if scope
76
- out
77
- end
78
- end
79
- end