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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.adoc +183 -154
- data/bin/console +1 -1
- data/grammars/basicdoc.rng +1516 -645
- data/grammars/biblio-standoc.rng +100 -20
- data/grammars/biblio.rng +959 -356
- data/grammars/versions.json +10 -10
- data/lib/relaton/bib/hash_parser_v1.rb +711 -0
- data/lib/relaton/bib/item_data.rb +168 -0
- data/lib/relaton/bib/model/address.rb +22 -0
- data/lib/relaton/bib/model/affiliation.rb +16 -0
- data/lib/relaton/bib/model/bibdata.rb +24 -0
- data/lib/relaton/bib/model/bibitem.rb +23 -0
- data/lib/relaton/bib/model/contact.rb +18 -0
- data/lib/relaton/bib/model/contribution_info.rb +16 -0
- data/lib/relaton/bib/model/contributor.rb +71 -0
- data/lib/relaton/bib/model/copyright.rb +27 -0
- data/lib/relaton/bib/model/date.rb +29 -0
- data/lib/relaton/bib/model/depiction.rb +14 -0
- data/lib/relaton/bib/model/docidentifier.rb +33 -0
- data/lib/relaton/bib/model/doctype.rb +14 -0
- data/lib/relaton/bib/model/edition.rb +14 -0
- data/lib/relaton/bib/model/editorial_group.rb +14 -0
- data/lib/relaton/bib/model/ext.rb +29 -0
- data/lib/relaton/bib/model/extent.rb +16 -0
- data/lib/relaton/bib/model/full_name_type.rb +64 -0
- data/lib/relaton/bib/model/fullname.rb +11 -0
- data/lib/relaton/bib/model/ics.rb +14 -0
- data/lib/relaton/bib/model/image.rb +28 -0
- data/lib/relaton/bib/model/item.rb +129 -0
- data/lib/relaton/bib/model/item_base.rb +19 -0
- data/lib/relaton/bib/model/keyword.rb +30 -0
- data/lib/relaton/bib/model/locality.rb +18 -0
- data/lib/relaton/bib/model/locality_stack.rb +14 -0
- data/lib/relaton/bib/model/localized_string.rb +57 -0
- data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
- data/lib/relaton/bib/model/logo.rb +12 -0
- data/lib/relaton/bib/model/medium.rb +22 -0
- data/lib/relaton/bib/model/note.rb +16 -0
- data/lib/relaton/bib/model/organization.rb +13 -0
- data/lib/relaton/bib/model/organization_type.rb +42 -0
- data/lib/relaton/bib/model/person.rb +36 -0
- data/lib/relaton/bib/model/phone.rb +14 -0
- data/lib/relaton/bib/model/place.rb +33 -0
- data/lib/relaton/bib/model/price.rb +14 -0
- data/lib/relaton/bib/model/relation.rb +43 -0
- data/lib/relaton/bib/model/series.rb +32 -0
- data/lib/relaton/bib/model/size.rb +23 -0
- data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
- data/lib/relaton/bib/model/status.rb +27 -0
- data/lib/relaton/bib/model/structured_identifier.rb +48 -0
- data/lib/relaton/bib/model/subdivision.rb +14 -0
- data/lib/relaton/bib/model/technical_committee.rb +14 -0
- data/lib/relaton/bib/model/title.rb +18 -0
- data/lib/relaton/bib/model/uri.rb +18 -0
- data/lib/relaton/bib/model/validity.rb +16 -0
- data/lib/relaton/bib/model/version.rb +14 -0
- data/lib/relaton/bib/model/workgroup.rb +20 -0
- data/lib/relaton/bib/parser/rfc_address.rb +60 -0
- data/lib/relaton/bib/parser/rfc_contacts.rb +35 -0
- data/lib/relaton/bib/parser/rfc_docidentifier.rb +70 -0
- data/lib/relaton/bib/parser/rfc_organization.rb +31 -0
- data/lib/relaton/bib/parser/rfc_person.rb +42 -0
- data/lib/relaton/bib/parser/rfc_reference.rb +143 -0
- data/lib/relaton/bib/parser/rfc_referencegroup.rb +45 -0
- data/lib/relaton/bib/parser/rfc_shared.rb +23 -0
- data/lib/relaton/bib/renderer/bibtex_builder.rb +348 -0
- data/lib/relaton/bib/renderer/rfc.rb +297 -0
- data/lib/relaton/bib/util.rb +18 -0
- data/lib/relaton/bib/version.rb +5 -0
- data/lib/{relaton_bib.rb → relaton/bib.rb} +47 -36
- data/lib/{relaton_bib → relaton}/bibtex_parser.rb +24 -27
- data/lib/{relaton_bib → relaton}/bibxml_parser.rb +43 -46
- data/lib/{relaton_bib → relaton}/hit.rb +3 -3
- data/lib/{relaton_bib → relaton}/hit_collection.rb +2 -2
- data/lib/{relaton_bib → relaton}/workers_pool.rb +1 -1
- data/lib/{relaton_bib → relaton}/xml_parser.rb +49 -51
- data/relaton-bib.gemspec +8 -8
- metadata +95 -74
- data/lib/relaton_bib/bib_item_locality.rb +0 -175
- data/lib/relaton_bib/biblio_note.rb +0 -72
- data/lib/relaton_bib/biblio_version.rb +0 -46
- data/lib/relaton_bib/bibliographic_date.rb +0 -119
- data/lib/relaton_bib/bibliographic_item.rb +0 -668
- data/lib/relaton_bib/bibliographic_size.rb +0 -103
- data/lib/relaton_bib/classification.rb +0 -40
- data/lib/relaton_bib/config.rb +0 -16
- data/lib/relaton_bib/contribution_info.rb +0 -117
- data/lib/relaton_bib/contributor.rb +0 -277
- data/lib/relaton_bib/copyright_association.rb +0 -79
- data/lib/relaton_bib/document_identifier.rb +0 -118
- data/lib/relaton_bib/document_relation.rb +0 -95
- data/lib/relaton_bib/document_relation_collection.rb +0 -57
- data/lib/relaton_bib/document_status.rb +0 -92
- data/lib/relaton_bib/document_type.rb +0 -52
- data/lib/relaton_bib/edition.rb +0 -55
- data/lib/relaton_bib/editorial_group.rb +0 -41
- data/lib/relaton_bib/extent.rb +0 -39
- data/lib/relaton_bib/forename.rb +0 -65
- data/lib/relaton_bib/formatted_ref.rb +0 -17
- data/lib/relaton_bib/formatted_string.rb +0 -133
- data/lib/relaton_bib/full_name.rb +0 -108
- data/lib/relaton_bib/hash_converter.rb +0 -568
- data/lib/relaton_bib/ics.rb +0 -42
- data/lib/relaton_bib/image.rb +0 -95
- data/lib/relaton_bib/localized_string.rb +0 -149
- data/lib/relaton_bib/medium.rb +0 -76
- data/lib/relaton_bib/organization.rb +0 -165
- data/lib/relaton_bib/person.rb +0 -129
- data/lib/relaton_bib/place.rb +0 -203
- data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
- data/lib/relaton_bib/renderer/bibxml.rb +0 -296
- data/lib/relaton_bib/series.rb +0 -119
- data/lib/relaton_bib/structured_identifier.rb +0 -173
- data/lib/relaton_bib/technical_committee.rb +0 -34
- data/lib/relaton_bib/typed_title_string.rb +0 -191
- data/lib/relaton_bib/typed_uri.rb +0 -57
- data/lib/relaton_bib/util.rb +0 -16
- data/lib/relaton_bib/validity.rb +0 -52
- data/lib/relaton_bib/version.rb +0 -3
- data/lib/relaton_bib/workgroup.rb +0 -58
- /data/lib/{relaton_bib → relaton}/deep_dup.rb +0 -0
@@ -1,149 +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) && content.none?
|
22
|
-
raise ArgumentError, "LocalizedString content is empty"
|
23
|
-
end
|
24
|
-
|
25
|
-
@language = language.is_a?(String) ? [language] : language
|
26
|
-
@script = script.is_a?(String) ? [script] : script
|
27
|
-
@content = if content.is_a?(Array)
|
28
|
-
content.map do |c|
|
29
|
-
case c
|
30
|
-
when Hash
|
31
|
-
LocalizedString.new c[:content], c[:language], c[:script]
|
32
|
-
when String then LocalizedString.new c
|
33
|
-
else c
|
34
|
-
end
|
35
|
-
end
|
36
|
-
else cleanup content
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def ==(other)
|
41
|
-
return false unless other.is_a? LocalizedString
|
42
|
-
|
43
|
-
content == other.content && language == other.language && script == other.script
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# String representation.
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
#
|
51
|
-
def to_s
|
52
|
-
content.is_a?(Array) ? content.first.to_s : content.to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
#
|
56
|
-
# Returns true if content is empty.
|
57
|
-
#
|
58
|
-
# @return [Boolean]
|
59
|
-
#
|
60
|
-
def empty?
|
61
|
-
content.empty?
|
62
|
-
end
|
63
|
-
|
64
|
-
# @param builder [Nokogiri::XML::Builder]
|
65
|
-
def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
66
|
-
return unless content
|
67
|
-
|
68
|
-
if content.is_a?(Array)
|
69
|
-
content.each { |c| builder.variant { c.to_xml builder } }
|
70
|
-
else
|
71
|
-
builder.parent["language"] = language.join(",") if language&.any?
|
72
|
-
builder.parent["script"] = script.join(",") if script&.any?
|
73
|
-
builder.parent.inner_html = encode content
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
#
|
78
|
-
# Encode content.
|
79
|
-
#
|
80
|
-
# @param [String] cnt content
|
81
|
-
#
|
82
|
-
# @return [String] encoded content
|
83
|
-
#
|
84
|
-
def encode(cnt)
|
85
|
-
escp cnt
|
86
|
-
end
|
87
|
-
|
88
|
-
#
|
89
|
-
# Escope HTML entities.
|
90
|
-
#
|
91
|
-
# @param [String] str input string
|
92
|
-
#
|
93
|
-
# @return [String] output string
|
94
|
-
#
|
95
|
-
def escp(str)
|
96
|
-
return unless str
|
97
|
-
|
98
|
-
coder = HTMLEntities.new
|
99
|
-
coder.encode coder.decode(str.dup.force_encoding("UTF-8"))
|
100
|
-
end
|
101
|
-
|
102
|
-
# @return [Hash, Array<Hash>]
|
103
|
-
def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
104
|
-
if content.nil? || content.is_a?(String)
|
105
|
-
# return content unless language || script
|
106
|
-
|
107
|
-
hash = {}
|
108
|
-
hash["content"] = content # unless content.nil? || content.empty?
|
109
|
-
hash["language"] = single_element_array(language) if language&.any?
|
110
|
-
hash["script"] = single_element_array(script) if script&.any?
|
111
|
-
hash
|
112
|
-
else content&.map &:to_hash
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# @param prefix [String]
|
117
|
-
# @param count [Integer] number of elements
|
118
|
-
# @return [String]
|
119
|
-
def to_asciibib(prefix = "", count = 1, has_attrs = false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
|
120
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
121
|
-
case content
|
122
|
-
when String
|
123
|
-
unless language&.any? || script&.any? || has_attrs
|
124
|
-
return "#{prefix}:: #{content}\n"
|
125
|
-
end
|
126
|
-
|
127
|
-
out = count > 1 ? "#{prefix}::\n" : ""
|
128
|
-
out += "#{pref}content:: #{content}\n"
|
129
|
-
language&.each { |l| out += "#{pref}language:: #{l}\n" }
|
130
|
-
script&.each { |s| out += "#{pref}script:: #{s}\n" }
|
131
|
-
out
|
132
|
-
when Array
|
133
|
-
content.map { |c| c.to_asciibib "#{pref}variant", content.size }.join
|
134
|
-
else count > 1 ? "#{prefix}::\n" : ""
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
#
|
139
|
-
# Should be implemented in subclass.
|
140
|
-
#
|
141
|
-
# @param [String] str content
|
142
|
-
#
|
143
|
-
# @return [String] cleaned content
|
144
|
-
#
|
145
|
-
def cleanup(str)
|
146
|
-
str
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
data/lib/relaton_bib/medium.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
module RelatonBib
|
2
|
-
class Medium
|
3
|
-
# @return [String, nil]
|
4
|
-
attr_reader :content, :genre, :form, :carrier, :size, :scale
|
5
|
-
|
6
|
-
#
|
7
|
-
# Initialize a Medium object.
|
8
|
-
#
|
9
|
-
# @param content [String, nil] content of the medium
|
10
|
-
# @param genre [String, nil] genre of the medium
|
11
|
-
# @param form [String, nil] form of the medium
|
12
|
-
# @param carrier [String, nil] carrier of the medium
|
13
|
-
# @param size [String, nil] size of the medium
|
14
|
-
# @param scale [String, nil]
|
15
|
-
#
|
16
|
-
def initialize(**args)
|
17
|
-
@content = args[:content]
|
18
|
-
@genre = args[:genre]
|
19
|
-
@form = args[:form]
|
20
|
-
@carrier = args[:carrier]
|
21
|
-
@size = args[:size]
|
22
|
-
@scale = args[:scale]
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# Render Medium object to XML.
|
27
|
-
#
|
28
|
-
# @param builder [Nokogiri::XML::Builder]
|
29
|
-
#
|
30
|
-
def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
31
|
-
builder.medium do
|
32
|
-
builder.content content if content
|
33
|
-
builder.genre genre if genre
|
34
|
-
builder.form form if form
|
35
|
-
builder.carrier carrier if carrier
|
36
|
-
builder.size size if size
|
37
|
-
builder.scale scale if scale
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Render Medium object to hash.
|
43
|
-
#
|
44
|
-
# @return [Hash]
|
45
|
-
#
|
46
|
-
def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
47
|
-
hash = {}
|
48
|
-
hash["content"] = content if content
|
49
|
-
hash["genre"] = genre if genre
|
50
|
-
hash["form"] = form if form
|
51
|
-
hash["carrier"] = carrier if carrier
|
52
|
-
hash["size"] = size if size
|
53
|
-
hash["scale"] = scale if scale
|
54
|
-
hash
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# Render Medium object to AsciiBib.
|
59
|
-
#
|
60
|
-
# @param prefix [String]
|
61
|
-
#
|
62
|
-
# @return [String]
|
63
|
-
#
|
64
|
-
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
65
|
-
pref = prefix.empty? ? "medium." : "#{prefix}.medium."
|
66
|
-
out = ""
|
67
|
-
out += "#{pref}content:: #{content}\n" if content
|
68
|
-
out += "#{pref}genre:: #{genre}\n" if genre
|
69
|
-
out += "#{pref}form:: #{form}\n" if form
|
70
|
-
out += "#{pref}carrier:: #{carrier}\n" if carrier
|
71
|
-
out += "#{pref}size:: #{size}\n" if size
|
72
|
-
out += "#{pref}scale:: #{scale}\n" if scale
|
73
|
-
out
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,165 +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]
|
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
|
-
def ==(other)
|
29
|
-
type == other.type && value == other.value
|
30
|
-
end
|
31
|
-
|
32
|
-
# @param builder [Nokogiri::XML::Builder]
|
33
|
-
def to_xml(builder)
|
34
|
-
builder.identifier(value, type: type)
|
35
|
-
end
|
36
|
-
|
37
|
-
# @return [Hash]
|
38
|
-
def to_hash
|
39
|
-
{ "type" => type, "id" => value }
|
40
|
-
end
|
41
|
-
|
42
|
-
# @param prefix [String]
|
43
|
-
# @param count [Integer]
|
44
|
-
# @return [String]
|
45
|
-
def to_asciibib(prefix = "", count = 1)
|
46
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
47
|
-
out = count > 1 ? "#{pref}identifier::\n" : ""
|
48
|
-
out += "#{pref}identifier.type:: #{type}\n"
|
49
|
-
out += "#{pref}identifier.value:: #{value}\n"
|
50
|
-
out
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Organization.
|
55
|
-
class Organization < Contributor
|
56
|
-
# @return [Array<RelatonBib::LocalizedString>]
|
57
|
-
attr_reader :name
|
58
|
-
|
59
|
-
# @return [RelatonBib::LocalizedString, nil]
|
60
|
-
attr_reader :abbreviation
|
61
|
-
|
62
|
-
# @return [Array<RelatonBib::LocalizedString>]
|
63
|
-
attr_reader :subdivision
|
64
|
-
|
65
|
-
# @return [Array<RelatonBib::OrgIdentifier>]
|
66
|
-
attr_reader :identifier
|
67
|
-
|
68
|
-
# @return [RelatonBib::Image, nil]
|
69
|
-
attr_reader :logo
|
70
|
-
|
71
|
-
# @param name [String, Hash, Array<String, Hash>]
|
72
|
-
# @param abbreviation [RelatoBib::LocalizedString, String]
|
73
|
-
# @param subdivision [Array<RelatoBib::LocalizedString>]
|
74
|
-
# @param url [String]
|
75
|
-
# @param identifier [Array<RelatonBib::OrgIdentifier>]
|
76
|
-
# @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
|
77
|
-
# @param logo [RelatonBib::Image, nil]
|
78
|
-
def initialize(**args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
79
|
-
raise ArgumentError, "missing keyword: name" unless args[:name]
|
80
|
-
|
81
|
-
super(url: args[:url], contact: args[:contact] || [])
|
82
|
-
|
83
|
-
@name = if args[:name].is_a?(Array)
|
84
|
-
args[:name].map { |n| localized_string(n) }
|
85
|
-
else
|
86
|
-
[localized_string(args[:name])]
|
87
|
-
end
|
88
|
-
|
89
|
-
@abbreviation = localized_string args[:abbreviation]
|
90
|
-
@subdivision = (args[:subdivision] || []).map do |sd|
|
91
|
-
localized_string sd
|
92
|
-
end
|
93
|
-
@identifier = args[:identifier] || []
|
94
|
-
@logo = args[:logo]
|
95
|
-
end
|
96
|
-
|
97
|
-
def ==(other)
|
98
|
-
name == other.name && abbreviation == other.abbreviation &&
|
99
|
-
subdivision == other.subdivision && identifier == other.identifier &&
|
100
|
-
logo == other.logo && super
|
101
|
-
end
|
102
|
-
|
103
|
-
# @param opts [Hash]
|
104
|
-
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
105
|
-
# @option opts [String] :lang language
|
106
|
-
def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
|
107
|
-
opts[:builder].organization do |builder|
|
108
|
-
nm = name.select { |n| n.language&.include? opts[:lang] }
|
109
|
-
nm = name unless nm.any?
|
110
|
-
nm.each { |n| builder.name { |b| n.to_xml b } }
|
111
|
-
sbdv = subdivision.select { |sd| sd.language&.include? opts[:lang] }
|
112
|
-
sbdv = subdivision unless sbdv.any?
|
113
|
-
sbdv.each { |sd| builder.subdivision { sd.to_xml builder } }
|
114
|
-
builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation
|
115
|
-
builder.uri url if uri
|
116
|
-
identifier.each { |identifier| identifier.to_xml builder }
|
117
|
-
super builder
|
118
|
-
builder.logo { |b| logo.to_xml b } if logo
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# @return [Hash]
|
123
|
-
def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
|
124
|
-
hash = { "name" => single_element_array(name) }
|
125
|
-
hash["abbreviation"] = abbreviation.to_hash if abbreviation
|
126
|
-
hash["identifier"] = single_element_array(identifier) if identifier&.any?
|
127
|
-
if subdivision&.any?
|
128
|
-
hash["subdivision"] = single_element_array(subdivision)
|
129
|
-
end
|
130
|
-
hash["logo"] = logo.to_hash if logo
|
131
|
-
{ "organization" => hash.merge(super) }
|
132
|
-
end
|
133
|
-
|
134
|
-
# @param prefix [String]
|
135
|
-
# @param count [Integer]
|
136
|
-
# @return [String]
|
137
|
-
def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
138
|
-
pref = prefix.sub(/\*$/, "organization")
|
139
|
-
out = count > 1 ? "#{pref}::\n" : ""
|
140
|
-
name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
|
141
|
-
out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
|
142
|
-
subdivision.each do |sd|
|
143
|
-
out += "#{pref}.subdivision::" if subdivision.size > 1
|
144
|
-
out += sd.to_asciibib "#{pref}.subdivision"
|
145
|
-
end
|
146
|
-
identifier.each { |n| out += n.to_asciibib pref, identifier.size }
|
147
|
-
out += super pref
|
148
|
-
out += logo.to_asciibib "#{pref}.logo" if logo
|
149
|
-
out
|
150
|
-
end
|
151
|
-
|
152
|
-
private
|
153
|
-
|
154
|
-
# @param arg [String, Hash, RelatoBib::LocalizedString]
|
155
|
-
# @return [RelatoBib::LocalizedString]
|
156
|
-
def localized_string(arg)
|
157
|
-
case arg
|
158
|
-
when String then LocalizedString.new(arg)
|
159
|
-
when Hash
|
160
|
-
LocalizedString.new(arg[:content], arg[:language], arg[:script])
|
161
|
-
when LocalizedString then arg
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
data/lib/relaton_bib/person.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RelatonBib
|
4
|
-
# Person identifier type.
|
5
|
-
module PersonIdentifierType
|
6
|
-
ISNI = "isni"
|
7
|
-
ORCID = "orcid"
|
8
|
-
URI = "uri"
|
9
|
-
|
10
|
-
# Checks type.
|
11
|
-
# @param type [String]
|
12
|
-
# @raise [ArgumentError] if type isn't "isni" or "uri"
|
13
|
-
def self.check(type)
|
14
|
-
unless [ISNI, ORCID, URI].include? type
|
15
|
-
raise ArgumentError, 'Invalid type. It should be "isni", "orcid", "\
|
16
|
-
"or "uri".'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Person identifier.
|
22
|
-
class PersonIdentifier
|
23
|
-
# @return [RelatonBib::PersonIdentifierType::ISNI,
|
24
|
-
# RelatonBib::PersonIdentifierType::ORCID,
|
25
|
-
# RelatonBib::PersonIdentifierType::URI]
|
26
|
-
attr_accessor :type
|
27
|
-
|
28
|
-
# @return [String]
|
29
|
-
attr_accessor :value
|
30
|
-
|
31
|
-
# @param type [RelatonBib::PersonIdentifierType::ISNI,
|
32
|
-
# RelatonBib::PersonIdentifierType::ORCID,
|
33
|
-
# RelatonBib::PersonIdentifierType::URI]
|
34
|
-
# @param value [String]
|
35
|
-
def initialize(type, value)
|
36
|
-
PersonIdentifierType.check type
|
37
|
-
|
38
|
-
@type = type
|
39
|
-
@value = value
|
40
|
-
end
|
41
|
-
|
42
|
-
# @param builser [Nokogiri::XML::Builder]
|
43
|
-
def to_xml(builder)
|
44
|
-
builder.identifier value, type: type
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [Hash]
|
48
|
-
def to_hash
|
49
|
-
{ "type" => type, "id" => value }
|
50
|
-
end
|
51
|
-
|
52
|
-
# @param prefix [String]
|
53
|
-
# @param count [Integer] number of ids
|
54
|
-
# @return [String]
|
55
|
-
def to_asciibib(prefix = "", count = 1)
|
56
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
57
|
-
out = count > 1 ? "#{prefix}::\n" : ""
|
58
|
-
out += "#{pref}type:: #{type}\n"
|
59
|
-
out += "#{pref}value:: #{value}\n"
|
60
|
-
out
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Person class.
|
65
|
-
class Person < Contributor
|
66
|
-
# @return [RelatonBib::FullName]
|
67
|
-
attr_accessor :name
|
68
|
-
|
69
|
-
# @return [Array<String>]
|
70
|
-
attr_reader :credential
|
71
|
-
|
72
|
-
# @return [Array<RelatonBib::Affiliation>]
|
73
|
-
attr_accessor :affiliation
|
74
|
-
|
75
|
-
# @return [Array<RelatonBib::PersonIdentifier>]
|
76
|
-
attr_accessor :identifier
|
77
|
-
|
78
|
-
# @param name [RelatonBib::FullName]
|
79
|
-
# @param credential [Array<String>]
|
80
|
-
# @param affiliation [Array<RelatonBib::Affiliation>]
|
81
|
-
# @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
|
82
|
-
# @param identifier [Array<RelatonBib::PersonIdentifier>]
|
83
|
-
# @param url [String, nil]
|
84
|
-
def initialize(name:, **args)
|
85
|
-
contact = args[:contact] || []
|
86
|
-
super(contact: contact, url: args[:url])
|
87
|
-
@name = name
|
88
|
-
@credential = args[:credential] || []
|
89
|
-
@affiliation = args[:affiliation] || []
|
90
|
-
@identifier = args[:identifier] || []
|
91
|
-
end
|
92
|
-
|
93
|
-
# @param opts [Hash]
|
94
|
-
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
95
|
-
# @option opts [String, Symbol] :lang language
|
96
|
-
def to_xml(**opts) # rubocop:disable Metrics/AbcSize
|
97
|
-
opts[:builder].person do |builder|
|
98
|
-
name.to_xml(**opts)
|
99
|
-
credential.each { |c| builder.credential c }
|
100
|
-
affiliation.each { |a| a.to_xml(**opts) }
|
101
|
-
identifier.each { |id| id.to_xml builder }
|
102
|
-
contact.each { |contact| contact.to_xml builder }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# @return [Hash]
|
107
|
-
def to_hash # rubocop:disable Metrics/AbcSize
|
108
|
-
hash = { "name" => name.to_hash }
|
109
|
-
hash["credential"] = credential if credential.any?
|
110
|
-
hash["affiliation"] = affiliation.map &:to_hash if affiliation.any?
|
111
|
-
hash["identifier"] = identifier.map &:to_hash if identifier.any?
|
112
|
-
{ "person" => hash.merge(super) }
|
113
|
-
end
|
114
|
-
|
115
|
-
# @param prefix [String]
|
116
|
-
# @count [Integer] number of persons
|
117
|
-
# @return [String]
|
118
|
-
def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
|
119
|
-
pref = prefix.sub(/\*$/, "person")
|
120
|
-
out = count > 1 ? "#{pref}::\n" : ""
|
121
|
-
out += name.to_asciibib pref
|
122
|
-
credential.each { |c| out += "#{pref}.credential:: #{c}\n" }
|
123
|
-
affiliation.each { |af| out += af.to_asciibib pref, affiliation.size }
|
124
|
-
identifier.each { |id| out += id.to_asciibib pref, identifier.size }
|
125
|
-
out += super pref
|
126
|
-
out
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|