Module: RelatonBib
- Defined in:
- lib/relaton_bib/contribution_info.rb,
lib/relaton_bib.rb,
lib/relaton_bib/medium.rb,
lib/relaton_bib/person.rb,
lib/relaton_bib/series.rb,
lib/relaton_bib/version.rb,
lib/relaton_bib/validity.rb,
lib/relaton_bib/typed_uri.rb,
lib/relaton_bib/xml_parser.rb,
lib/relaton_bib/biblio_note.rb,
lib/relaton_bib/contributor.rb,
lib/relaton_bib/hash_to_bib.rb,
lib/relaton_bib/organization.rb,
lib/relaton_bib/workers_pool.rb,
lib/relaton_bib/formatted_ref.rb,
lib/relaton_bib/biblio_version.rb,
lib/relaton_bib/classification.rb,
lib/relaton_bib/document_status.rb,
lib/relaton_bib/formatted_string.rb,
lib/relaton_bib/localized_string.rb,
lib/relaton_bib/bib_item_locality.rb,
lib/relaton_bib/document_relation.rb,
lib/relaton_bib/bibliographic_date.rb,
lib/relaton_bib/bibliographic_item.rb,
lib/relaton_bib/typed_title_string.rb,
lib/relaton_bib/document_identifier.rb,
lib/relaton_bib/copyright_association.rb,
lib/relaton_bib/document_relation_collection.rb
Overview
Defined Under Namespace
Modules: PersonIdentifierType
Classes: Address, Affilation, BibItemLocality, BiblioNote, BibliographicDate, BibliographicItem, Classification, Contact, ContributionInfo, Contributor, ContributorRole, CopyrightAssociation, DocRelationCollection, DocumentIdentifier, DocumentRelation, DocumentStatus, Error, FormattedRef, FormattedString, FullName, LocalizedString, Medium, OrgIdentifier, Organization, Person, PersonIdentifier, RequestError, Series, TypedTitleString, TypedUri, Validity, WorkersPool, XMLParser
Constant Summary
collapse
- VERSION =
"0.2.5".freeze
Class Method Summary
collapse
Class Method Details
.abstract_hash_to_bib(ret) ⇒ Object
56
57
58
59
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 56
def abstract_hash_to_bib(ret)
return unless ret[:abstract]
ret[:abstract] = array(ret[:abstract])
end
|
.accesslocation_hash_to_bib(ret) ⇒ Object
71
72
73
74
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 71
def accesslocation_hash_to_bib(ret)
return unless ret[:accesslocation]
ret[:accesslocation] = array(ret[:accesslocation])
end
|
.affiliation_hash_to_bib(c) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/relaton_bib/contributor.rb', line 7
def affiliation_hash_to_bib(c)
return [] unless c[:affiliation]
array(c[:affiliation]).map do |a|
a[:description] = array(a[:description])&.map do |d|
FormattedString.new(d.nil? ? { content: nil } :
{ content: d[:content], language: d[:language],
script: d[:language], format: d[:format] })
end
Affilation.new(
Organization.new(org_hash_to_bib(a[:organization])), a[:description])
end
end
|
.array(a) ⇒ Object
42
43
44
45
46
|
# File 'lib/relaton_bib/hash_to_bib.rb', line 42
def array(a)
return [] unless a
return [a] unless a.is_a?(Array)
a
end
|
.biblionote_hash_to_bib(ret) ⇒ Object
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/relaton_bib/biblio_note.rb', line 3
def biblionote_hash_to_bib(ret)
return unless ret[:biblionote]
ret[:biblionote] = array(ret[:biblionote])
(ret[:biblionote])&.each_with_index do |n, i|
ret[:biblionote][i] =
BiblioNote.new(content: n[:content], type: n[:type],
language: n[:language],
script: n[:script], format: n[:format])
end
end
|
.classification_hash_to_bib(ret) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/relaton_bib/classification.rb', line 3
def classification_hash_to_bib(ret)
ret[:classification] and
ret[:classification] = Classification.new(ret[:classification])
end
|
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/relaton_bib/contributor.rb', line 20
def contacts_hash_to_bib(c)
return [] unless c[:contacts]
array(c[:contacts]).map do |a|
(a[:city] || a[:country]) ?
RelatonBib::Address.new(
street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
country: a[:country], state: a[:state]) :
RelatonBib::Contact.new(type: a[:type], value: a[:value])
end
end
|
.contributors_hash_to_bib(ret) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/relaton_bib/contribution_info.rb', line 8
def contributors_hash_to_bib(ret)
return unless ret[:contributors]
ret[:contributors] = array(ret[:contributors])
ret[:contributors]&.each_with_index do |c, i|
ret[:contributors][i][:roles] = array(ret[:contributors][i][:roles])
ret[:contributors][i][:entity] = c[:person] ?
person_hash_to_bib(c[:person]) : org_hash_to_bib(c[:organization])
ret[:contributors][i].delete(:person)
ret[:contributors][i].delete(:organization)
end
end
|
.dates_hash_to_bib(ret) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/relaton_bib/bibliographic_date.rb', line 7
def dates_hash_to_bib(ret)
return unless ret[:dates]
ret[:dates] = array(ret[:dates])
ret[:dates].each_with_index do |d, i|
if d[:value]
ret[:dates][i][:on] ||= d[:value]
ret[:dates][i].delete(:value)
end
end
end
|
.docid_hash_to_bib(ret) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/relaton_bib/document_identifier.rb', line 5
def docid_hash_to_bib(ret)
return unless ret[:docid]
ret[:docid] = array(ret[:docid])
ret[:docid]&.each_with_index do |id, i|
ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: id[:type])
end
end
|
.docstatus_hash_to_bib(ret) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/relaton_bib/document_status.rb', line 7
def docstatus_hash_to_bib(ret)
ret[:docstatus] and ret[:docstatus] =
DocumentStatus.new(stage: ret[:docstatus][:stage],
substage: ret[:docstatus][:substage],
iteration: ret[:docstatus][:iteration])
end
|
.extent_hash_to_bib(ret) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 28
def extent_hash_to_bib(ret)
return unless ret[:extent]
ret[:extent] = array(ret[:extent])
ret[:extent]&.each_with_index do |e, i|
ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
e[:reference_to])
end
end
|
5
6
7
8
|
# File 'lib/relaton_bib/formatted_ref.rb', line 5
def formattedref_hash_to_bib(ret)
ret[:formattedref] and ret[:formattedref] =
formattedref(ret[:formattedref])
end
|
.fullname_hash_to_bib(c) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/relaton_bib/person.rb', line 16
def fullname_hash_to_bib(c)
n = c[:name]
FullName.new(
forenames: array(n[:forenames])&.map { |f| localname(f, c) },
initials: array(n[:initials])&.map { |f| localname(f, c) },
additions: array(n[:additions])&.map { |f| localname(f, c) },
prefix: array(n[:prefix])&.map { |f| localname(f, c) },
surname: localname(n[:surname], c),
completename: localname(n[:completename], c),
)
end
|
.hash_to_bib(args, nested = false) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/relaton_bib/hash_to_bib.rb', line 3
def hash_to_bib(args, nested = false)
return nil unless args.is_a?(Hash)
ret = Marshal.load(Marshal.dump(symbolize(args))) timestamp_hash(ret) unless nested
title_hash_to_bib(ret)
link_hash_to_bib(ret)
language_hash_to_bib(ret)
script_hash_to_bib(ret)
dates_hash_to_bib(ret)
docid_hash_to_bib(ret)
version_hash_to_bib(ret)
biblionote_hash_to_bib(ret)
abstract_hash_to_bib(ret)
formattedref_hash_to_bib(ret)
docstatus_hash_to_bib(ret)
contributors_hash_to_bib(ret)
relations_hash_to_bib(ret)
series_hash_to_bib(ret)
medium_hash_to_bib(ret)
place_hash_to_bib(ret)
extent_hash_to_bib(ret)
accesslocation_hash_to_bib(ret)
classification_hash_to_bib(ret)
validity_hash_to_bib(ret)
ret
end
|
.language_hash_to_bib(ret) ⇒ Object
46
47
48
49
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 46
def language_hash_to_bib(ret)
return unless ret[:language]
ret[:language] = array(ret[:language])
end
|
.link_hash_to_bib(ret) ⇒ Object
61
62
63
64
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 61
def link_hash_to_bib(ret)
return unless ret[:link]
ret[:link] = array(ret[:link])
end
|
.localizedstring(f) ⇒ Object
.localname(f, c) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/relaton_bib/hash_to_bib.rb', line 48
def localname(f, c)
return nil if f.nil?
f.is_a?(Hash) and lang = f[:language]
lang ||= c[:name][:language]
f.is_a?(Hash) and script = f[:script]
script ||= c[:name][:script]
f.is_a?(Hash) ?
RelatonBib::LocalizedString.new(f[:content], lang, script) :
RelatonBib::LocalizedString.new(f, lang, script)
end
|
.medium_hash_to_bib(ret) ⇒ Object
3
4
5
|
# File 'lib/relaton_bib/medium.rb', line 3
def medium_hash_to_bib(ret)
ret[:medium] and ret[:medium] = Medium.new(ret[:medium])
end
|
.org_hash_to_bib(c) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/relaton_bib/organization.rb', line 7
def org_hash_to_bib(c)
return nil if c.nil?
c[:identifiers] = array(c[:identifiers])&.map do |a|
OrgIdentifier.new(a[:type], a[:id])
end
c
end
|
.person_hash_to_bib(c) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/relaton_bib/person.rb', line 7
def person_hash_to_bib(c)
Person.new(
name: fullname_hash_to_bib(c),
affiliation: affiliation_hash_to_bib(c),
contacts: contacts_hash_to_bib(c),
identifiers: person_identifiers_hash_to_bib(c),
)
end
|
.person_identifiers_hash_to_bib(c) ⇒ Object
28
29
30
31
32
|
# File 'lib/relaton_bib/person.rb', line 28
def person_identifiers_hash_to_bib(c)
array(c[:identifiers])&.map do |a|
PersonIdentifier.new(a[:type], a[:id])
end
end
|
.place_hash_to_bib(ret) ⇒ Object
66
67
68
69
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 66
def place_hash_to_bib(ret)
return unless ret[:place]
ret[:place] = array(ret[:place])
end
|
.relation_bibitem_hash_to_bib(ret, r, i) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/relaton_bib/document_relation.rb', line 24
def relation_bibitem_hash_to_bib(ret, r, i)
if r[:bibitem] then ret[:relations][i][:bibitem] =
BibliographicItem.new(hash_to_bib(r[:bibitem], true))
else
warn "bibitem missing: #{r}"
ret[:relations][i][:bibitem] = nil
end
end
|
.relation_biblocality_hash_to_bib(ret, r, i) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/relaton_bib/document_relation.rb', line 33
def relation_biblocality_hash_to_bib(ret, r, i)
ret[:relations][i][:bib_locality] =
array(r[:bib_locality])&.map do |bl|
BibItemLocality.new(bl[:type], bl[:reference_from],
bl[:reference_to])
end
end
|
.relations_hash_to_bib(ret) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/relaton_bib/document_relation.rb', line 15
def relations_hash_to_bib(ret)
return unless ret[:relations]
ret[:relations] = array(ret[:relations])
ret[:relations]&.each_with_index do |r, i|
relation_bibitem_hash_to_bib(ret, r, i)
relation_biblocality_hash_to_bib(ret, r, i)
end
end
|
.script_hash_to_bib(ret) ⇒ Object
51
52
53
54
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 51
def script_hash_to_bib(ret)
return unless ret[:script]
ret[:script] = array(ret[:script])
end
|
.series_hash_to_bib(ret) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/relaton_bib/series.rb', line 5
def series_hash_to_bib(ret)
array(ret[:series])&.each_with_index do |s, i|
s[:formattedref] and s[:formattedref] = formattedref(s[:formattedref])
if s[:title]
s[:title] = { content: s[:title] } unless s.is_a?(Hash)
s[:title] = TypedTitleString.new(s[:title])
end
s[:abbreviation] and
s[:abbreviation] = localizedstring(s[:abbreviation])
ret[:series][i] = Series.new(s)
end
end
|
.symbolize(obj) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/relaton_bib/hash_to_bib.rb', line 34
def symbolize(obj)
obj.is_a? Hash and
return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo}
obj.is_a? Array and
return obj.inject([]){|memo,v | memo << symbolize(v); memo}
return obj
end
|
.timestamp_hash(ret) ⇒ Object
30
31
32
|
# File 'lib/relaton_bib/hash_to_bib.rb', line 30
def timestamp_hash(ret)
ret[:fetched] ||= Date.today.to_s
end
|
.title_hash_to_bib(ret) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 37
def title_hash_to_bib(ret)
return unless ret[:titles]
ret[:titles] = array(ret[:titles])
ret[:titles] = ret[:titles].map do |t|
t.is_a?(Hash) ? t : { content: t, language: "en", script: "Latn",
format: "text/plain", type: "main" }
end
end
|
.validity_hash_to_bib(ret) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/relaton_bib/validity.rb', line 3
def validity_hash_to_bib(ret)
return unless ret[:validity]
ret[:validity][:begins] and b = Time.parse(ret[:validity][:begins])
ret[:validity][:ends] and e = Time.parse(ret[:validity][:ends])
ret[:validity][:revision] and r = Time.parse(ret[:validity][:revision])
ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
end
|
.version_hash_to_bib(ret) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/relaton_bib/biblio_version.rb', line 4
def version_hash_to_bib(ret)
return unless ret[:version]
ret[:version][:draft] = array(ret[:version][:draft])
ret[:version] and ret[:version] = BibliographicItem::Version.new(
ret[:version][:revision_date], ret[:version][:draft])
end
|