Class: Bolognese::Metadata
- Inherits:
-
Object
- Object
- Bolognese::Metadata
show all
- Includes:
- MetadataUtils
- Defined in:
- lib/bolognese/metadata.rb
Constant Summary
Readers::SchemaOrgReader::SO_TO_DC_RELATION_TYPES
Readers::RisReader::RIS_TO_BIB_TRANSLATIONS, Readers::RisReader::RIS_TO_CP_TRANSLATIONS, Readers::RisReader::RIS_TO_SO_TRANSLATIONS
Readers::CrossrefReader::CONTACT_EMAIL
Readers::CiteprocReader::CP_TO_RIS_TRANSLATIONS, Readers::CiteprocReader::CP_TO_SO_TRANSLATIONS
Readers::BibtexReader::BIB_TO_CP_TRANSLATIONS, Readers::BibtexReader::BIB_TO_RIS_TRANSLATIONS, Readers::BibtexReader::BIB_TO_SO_TRANSLATIONS
Constants included
from Utils
Utils::BIB_TO_CR_TRANSLATIONS, Utils::CR_TO_BIB_TRANSLATIONS, Utils::CR_TO_CP_TRANSLATIONS, Utils::CR_TO_JATS_TRANSLATIONS, Utils::CR_TO_RIS_TRANSLATIONS, Utils::CR_TO_SO_TRANSLATIONS, Utils::DC_TO_CP_TRANSLATIONS, Utils::DC_TO_RIS_TRANSLATIONS, Utils::DC_TO_SO_TRANSLATIONS, Utils::LICENSE_NAMES, Utils::SO_TO_BIB_TRANSLATIONS, Utils::SO_TO_CP_TRANSLATIONS, Utils::SO_TO_DC_TRANSLATIONS, Utils::SO_TO_JATS_TRANSLATIONS, Utils::SO_TO_RIS_TRANSLATIONS
Constants included
from AuthorUtils
AuthorUtils::IDENTIFIER_SCHEME_URIS
Instance Attribute Summary collapse
#doc, #from, #issue, #locale, #meta, #name_detector, #page_end, #page_start, #regenerate, #reverse, #sandbox, #string, #style
Instance Method Summary
collapse
#citeproc_hsh, #first_page, #graph, #last_page, #raw, #should_passthru, #volume
#turtle
#schema_hsh, #schema_org
#ris
#rdf_xml
#date, #insert_authors, #insert_citation, #insert_citation_title, #insert_contributor, #insert_editors, #insert_fpage, #insert_issue, #insert_lpage, #insert_pub_id, #insert_publication_date, #insert_publisher_name, #insert_source, #insert_version, #insert_volume, #is_article?, #is_chapter?, #is_data?, #jats, #publication_type
#datacite_json
#datacite
#crossref
#crosscite
#codemeta
#citeproc
#citation
#bibtex
#get_schema_org, #read_schema_org, #schema_org_has_part, #schema_org_is_identical_to, #schema_org_is_new_version_of, #schema_org_is_part_of, #schema_org_is_previous_version_of, #schema_org_is_referenced_by, #schema_org_is_supplement_to, #schema_org_is_supplemented_by, #schema_org_references, #schema_org_related_identifier, #schema_org_reverse_related_identifier
#read_ris, #ris_meta
#read_datacite_json
#get_datacite, #read_datacite, #set_periodical
#crossref_alternate_identifiers, #crossref_date_published, #crossref_description, #crossref_funding_reference, #crossref_is_part_of, #crossref_license, #crossref_people, #crossref_references, #get_crossref, #read_crossref
#read_crosscite
#get_codemeta, #read_codemeta
#read_citeproc
#read_bibtex
Methods included from Utils
#find_from_format, #find_from_format_by_ext, #find_from_format_by_id, #find_from_format_by_string, #from_citeproc, #from_datacite_json, #from_schema_org, #get_contributor, #get_date, #get_date_from_date_parts, #get_date_from_parts, #get_date_parts, #get_date_parts_from_parts, #get_datetime_from_iso8601, #get_year_month, #get_year_month_day, #github_as_codemeta_url, #github_as_owner_url, #github_as_release_url, #github_as_repo_url, #github_from_url, #github_owner_from_url, #github_release_from_url, #github_repo_from_url, #jsonlint, #map_hash_keys, #normalize_id, #normalize_ids, #normalize_licenses, #normalize_orcid, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #sanitize, #to_citeproc, #to_datacite_json, #to_identifier, #to_ris, #to_schema_org, #to_schema_org_container, #to_schema_org_funder, #to_schema_org_identifier, #to_schema_org_relation, #to_schema_org_spatial_coverage, #validate_orcid, #validate_orcid_scheme, #validate_url
#datacite_errors, #datacite_xml, #insert_alternate_identifiers, #insert_contributors, #insert_creators, #insert_dates, #insert_descriptions, #insert_funding_references, #insert_identifier, #insert_person, #insert_publication_year, #insert_publisher, #insert_related_identifiers, #insert_resource_type, #insert_rights_list, #insert_subjects, #insert_titles, #insert_version, #insert_work, #root_attributes
#authors_as_string, #cleanup_author, #get_authors, #get_name_identifiers, #get_one_author, #is_personal_name?, #name_exists?
Methods included from DoiUtils
#doi_as_url, #doi_from_url, #doi_resolver, #doi_search, #get_doi_ra, #normalize_doi, #validate_doi, #validate_prefix
Constructor Details
#initialize(input: nil, from: nil, **options) ⇒ Metadata
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/bolognese/metadata.rb', line 16
def initialize(input: nil, from: nil, **options)
id = normalize_id(input, options)
if id.present?
@from = from || find_from_format(id: id)
hsh = @from.present? ? send("get_" + @from, id: id, sandbox: options[:sandbox]) : {}
string = hsh.fetch("string", nil)
elsif input.present? && File.exist?(input)
ext = File.extname(input)
if %w(.bib .ris .xml .json).include?(ext)
hsh = { "url" => options[:url],
"state" => options[:state],
"date_registered" => options[:date_registered],
"date_updated" => options[:date_updated],
"provider_id" => options[:provider_id],
"client_id" => options[:client_id],
"content_url" => options[:content_url] }
string = IO.read(input)
@from = from || find_from_format(string: string, ext: ext)
else
$stderr.puts "File type #{ext} not supported"
exit 1
end
else
hsh = { "url" => options[:url],
"state" => options[:state],
"date_registered" => options[:date_registered],
"date_updated" => options[:date_updated],
"provider_id" => options[:provider_id],
"client_id" => options[:client_id],
"content_url" => options[:content_url] }
string = input
@from = from || find_from_format(string: string)
end
string = string.force_encoding("UTF-8") if string.present?
@string = string
@style = options[:style]
@locale = options[:locale]
@regenerate = options[:regenerate]
@sandbox = options[:sandbox]
@url = hsh.to_h["url"].presence || options[:url].presence
@state = hsh.to_h["state"].presence
@date_registered = hsh.to_h["date_registered"].presence
@date_updated = hsh.to_h["date_updated"].presence
@provider_id = hsh.to_h["provider_id"].presence
@client_id = hsh.to_h["client_id"].presence
@content_url = hsh.to_h["content_url"].presence
@meta = @from.present? ? send("read_" + @from, string: string, sandbox: options[:sandbox]) : {}
@identifier = normalize_doi(options[:doi] || input, options) || @meta.fetch("id", nil) || @meta.fetch("identifier", nil)
end
|
Instance Attribute Details
#alternate_identifiers ⇒ Object
171
172
173
|
# File 'lib/bolognese/metadata.rb', line 171
def alternate_identifiers
@alternate_identifiers ||= meta.fetch("alternate_identifiers", nil)
end
|
#client_id ⇒ Object
90
91
92
|
# File 'lib/bolognese/metadata.rb', line 90
def client_id
@client_id ||= meta.fetch("client_id", nil)
end
|
#content_url ⇒ Object
175
176
177
|
# File 'lib/bolognese/metadata.rb', line 175
def content_url
@content_url ||= meta.fetch("content_url", nil)
end
|
#contributor ⇒ Object
203
204
205
|
# File 'lib/bolognese/metadata.rb', line 203
def contributor
@contributor ||= meta.fetch("contributor", nil)
end
|
#creator ⇒ Object
199
200
201
|
# File 'lib/bolognese/metadata.rb', line 199
def creator
@creator ||= meta.fetch("creator", nil)
end
|
#dates ⇒ Object
163
164
165
|
# File 'lib/bolognese/metadata.rb', line 163
def dates
@dates ||= meta.fetch("dates", nil)
end
|
#descriptions ⇒ Object
107
108
109
|
# File 'lib/bolognese/metadata.rb', line 107
def descriptions
@descriptions ||= meta.fetch("descriptions", nil)
end
|
#doi ⇒ Object
82
83
84
|
# File 'lib/bolognese/metadata.rb', line 82
def doi
@doi ||= @identifier.present? ? doi_from_url(@identifier) : meta.fetch("doi", nil)
end
|
#first_page=(value) ⇒ Object
Sets the attribute first_page
9
10
11
|
# File 'lib/bolognese/metadata.rb', line 9
def first_page=(value)
@first_page = value
end
|
Sets the attribute format
9
10
11
|
# File 'lib/bolognese/metadata.rb', line 9
def format=(value)
@format = value
end
|
127
128
129
|
# File 'lib/bolognese/metadata.rb', line 127
def formats
@formats ||= meta.fetch("formats", nil)
end
|
#funding_references ⇒ Object
135
136
137
|
# File 'lib/bolognese/metadata.rb', line 135
def funding_references
@funding_references ||= meta.fetch("funding_references", nil)
end
|
#geo_locations ⇒ Object
159
160
161
|
# File 'lib/bolognese/metadata.rb', line 159
def geo_locations
@geo_locations ||= meta.fetch("geo_locations", nil)
end
|
#id ⇒ Object
78
79
80
|
# File 'lib/bolognese/metadata.rb', line 78
def id
@id ||= meta.fetch("id", nil)
end
|
#identifier ⇒ Object
187
188
189
|
# File 'lib/bolognese/metadata.rb', line 187
def identifier
@identifier ||= meta.fetch("id", nil)
end
|
#language ⇒ Object
119
120
121
|
# File 'lib/bolognese/metadata.rb', line 119
def language
@language ||= meta.fetch("language", nil)
end
|
#last_page=(value) ⇒ Object
Sets the attribute last_page
9
10
11
|
# File 'lib/bolognese/metadata.rb', line 9
def last_page=(value)
@last_page = value
end
|
9
10
11
|
# File 'lib/bolognese/metadata.rb', line 9
def meta=(value)
@meta = value
end
|
#periodical ⇒ Object
155
156
157
|
# File 'lib/bolognese/metadata.rb', line 155
def periodical
@periodical ||= meta.fetch("periodical", nil)
end
|
#provider_id ⇒ Object
86
87
88
|
# File 'lib/bolognese/metadata.rb', line 86
def provider_id
@provider_id ||= meta.fetch("provider_id", nil)
end
|
#publication_year ⇒ Object
151
152
153
|
# File 'lib/bolognese/metadata.rb', line 151
def publication_year
@publication_year ||= meta.fetch("publication_year", nil)
end
|
#publisher ⇒ Object
167
168
169
|
# File 'lib/bolognese/metadata.rb', line 167
def publisher
@publisher ||= meta.fetch("publisher", nil)
end
|
139
140
141
|
# File 'lib/bolognese/metadata.rb', line 139
def related_identifiers
@related_identifiers ||= meta.fetch("related_identifiers", nil)
end
|
#rights_list ⇒ Object
111
112
113
|
# File 'lib/bolognese/metadata.rb', line 111
def rights_list
@rights_list ||= meta.fetch("rights_list", nil)
end
|
#schema_version ⇒ Object
131
132
133
|
# File 'lib/bolognese/metadata.rb', line 131
def schema_version
@schema_version ||= meta.fetch("schema_version", nil)
end
|
#sizes ⇒ Object
123
124
125
|
# File 'lib/bolognese/metadata.rb', line 123
def sizes
@sizes ||= meta.fetch("sizes", nil)
end
|
#source ⇒ Object
179
180
181
|
# File 'lib/bolognese/metadata.rb', line 179
def source
@source ||= meta.fetch("source", nil)
end
|
#state ⇒ Object
183
184
185
|
# File 'lib/bolognese/metadata.rb', line 183
def state
@state ||= meta.fetch("state", nil)
end
|
#subjects ⇒ Object
115
116
117
|
# File 'lib/bolognese/metadata.rb', line 115
def subjects
@subjects ||= meta.fetch("subjects", nil)
end
|
#titles ⇒ Object
195
196
197
|
# File 'lib/bolognese/metadata.rb', line 195
def titles
@titles ||= meta.fetch("titles", nil)
end
|
#types ⇒ Object
191
192
193
|
# File 'lib/bolognese/metadata.rb', line 191
def types
@types ||= meta.fetch("types", nil)
end
|
#url ⇒ Object
143
144
145
|
# File 'lib/bolognese/metadata.rb', line 143
def url
@url ||= meta.fetch("url", nil)
end
|
#version ⇒ Object
147
148
149
|
# File 'lib/bolognese/metadata.rb', line 147
def version
@version ||= meta.fetch("version", nil)
end
|
#volume=(value) ⇒ Object
Sets the attribute volume
9
10
11
|
# File 'lib/bolognese/metadata.rb', line 9
def volume=(value)
@volume = value
end
|
Instance Method Details
#errors ⇒ Object
validate against DataCite schema, unless there are already errors in the reader
103
104
105
|
# File 'lib/bolognese/metadata.rb', line 103
def errors
meta.fetch("errors", nil) || datacite_errors(xml: datacite, schema_version: schema_version)
end
|
#exists? ⇒ Boolean
94
95
96
|
# File 'lib/bolognese/metadata.rb', line 94
def exists?
(@state || meta.fetch("state", "not_found")) != "not_found"
end
|
#valid? ⇒ Boolean
98
99
100
|
# File 'lib/bolognese/metadata.rb', line 98
def valid?
exists? && errors.nil?
end
|