Class: Bolognese::Metadata
- Inherits:
-
Object
- Object
- Bolognese::Metadata
- Includes:
- MetadataUtils, Utils
- Defined in:
- lib/bolognese/metadata.rb
Constant Summary
Constants included from Utils
Utils::BIB_TO_CR_TRANSLATIONS, Utils::BIB_TO_DC_TRANSLATIONS, Utils::CP_TO_DC_TRANSLATIONS, Utils::CR_TO_BIB_TRANSLATIONS, Utils::CR_TO_CP_TRANSLATIONS, Utils::CR_TO_DC_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::NORMALIZED_LICENSES, Utils::RESOURCE_PATHS, Utils::RIS_TO_DC_TRANSLATIONS, 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, Utils::UNKNOWN_INFORMATION
Constants included from Readers::SchemaOrgReader
Readers::SchemaOrgReader::SO_TO_DC_RELATION_TYPES, Readers::SchemaOrgReader::SO_TO_DC_REVERSE_RELATION_TYPES
Constants included from Readers::RisReader
Readers::RisReader::RIS_TO_BIB_TRANSLATIONS, Readers::RisReader::RIS_TO_CP_TRANSLATIONS, Readers::RisReader::RIS_TO_SO_TRANSLATIONS
Constants included from Readers::CrossrefReader
Readers::CrossrefReader::CR_TO_DC_CONTRIBUTOR_TYPES
Constants included from Readers::CiteprocReader
Readers::CiteprocReader::CP_TO_RIS_TRANSLATIONS, Readers::CiteprocReader::CP_TO_SO_TRANSLATIONS
Constants included from Readers::BibtexReader
Readers::BibtexReader::BIB_TO_CP_TRANSLATIONS, Readers::BibtexReader::BIB_TO_RIS_TRANSLATIONS, Readers::BibtexReader::BIB_TO_SO_TRANSLATIONS
Constants included from AuthorUtils
AuthorUtils::IDENTIFIER_SCHEME_URIS
Instance Attribute Summary collapse
- #agency ⇒ Object
- #client_id ⇒ Object
- #container ⇒ Object
- #content_url ⇒ Object
-
#contributor ⇒ Object
writeonly
Sets the attribute contributor.
- #contributors ⇒ Object
- #creators ⇒ Object
- #date_registered ⇒ Object
- #dates ⇒ Object
- #descriptions ⇒ Object
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
- #doi ⇒ Object
-
#format ⇒ Object
writeonly
Sets the attribute format.
- #formats ⇒ Object
-
#from ⇒ Object
Returns the value of attribute from.
- #funding_references ⇒ Object
- #geo_locations ⇒ Object
- #id ⇒ Object
- #identifiers ⇒ Object
-
#issue ⇒ Object
Returns the value of attribute issue.
- #language ⇒ Object
-
#locale ⇒ Object
writeonly
Sets the attribute locale.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#page_end ⇒ Object
readonly
Returns the value of attribute page_end.
-
#page_start ⇒ Object
readonly
Returns the value of attribute page_start.
- #provider_id ⇒ Object
- #publication_year ⇒ Object
- #publisher ⇒ Object
-
#regenerate ⇒ Object
Returns the value of attribute regenerate.
- #related_identifiers ⇒ Object
- #related_items ⇒ Object
- #rights_list ⇒ Object
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
- #schema_version ⇒ Object
-
#show_errors ⇒ Object
Returns the value of attribute show_errors.
- #sizes ⇒ Object
- #state ⇒ Object
-
#string ⇒ Object
Returns the value of attribute string.
-
#style ⇒ Object
writeonly
Sets the attribute style.
- #subjects ⇒ Object
- #titles ⇒ Object
- #types ⇒ Object
- #url ⇒ Object
- #version_info ⇒ Object
-
#volume ⇒ Object
writeonly
Sets the attribute volume.
Attributes included from MetadataUtils
Instance Method Summary collapse
-
#errors ⇒ Object
validate against DataCite schema, unless there are already errors in the reader.
- #exists? ⇒ Boolean
-
#initialize(options = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #valid? ⇒ Boolean
Methods included from Utils
#abstract_description, #dfg_ids_to_fos, #find_from_format, #find_from_format_by_ext, #find_from_format_by_filename, #find_from_format_by_id, #find_from_format_by_string, #from_citeproc, #from_datacite_json, #from_schema_org, #from_schema_org_contributors, #from_schema_org_creators, #generate_container, #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_datetime_from_time, #get_identifier, #get_identifier_type, #get_iso8601_date, #get_series_information, #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, #hsh_to_fos, #hsh_to_spdx, #jsonlint, #map_hash_keys, #name_to_fos, #name_to_spdx, #normalize_cc_url, #normalize_id, #normalize_ids, #normalize_issn, #normalize_licenses, #normalize_orcid, #normalize_publisher, #normalize_ror, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #resource_file, #resource_json, #resources_dir_path, #sanitize, #to_citeproc, #to_datacite_json, #to_identifier, #to_ris, #to_schema_org, #to_schema_org_container, #to_schema_org_contributors, #to_schema_org_creators, #to_schema_org_funder, #to_schema_org_identifiers, #to_schema_org_relation, #to_schema_org_spatial_coverage, #validate_orcid, #validate_orcid_scheme, #validate_ror, #validate_url
Methods included from MetadataUtils
#citeproc_hsh, #container_title, #crosscite_hsh, #graph, #locale, #raw, #should_passthru, #style
Methods included from Writers::TurtleWriter
Methods included from Writers::SchemaOrgWriter
Methods included from Writers::RisWriter
Methods included from Writers::RdfXmlWriter
Methods included from Writers::JatsWriter
#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
Methods included from Writers::DataciteJsonWriter
Methods included from Writers::DataciteWriter
Methods included from Writers::CsvWriter
Methods included from Writers::CrossrefWriter
Methods included from Writers::CrossciteWriter
Methods included from Writers::CodemetaWriter
Methods included from Writers::CiteprocWriter
Methods included from Writers::CitationWriter
Methods included from Writers::BibtexWriter
Methods included from Readers::SchemaOrgReader
#get_schema_org, #read_schema_org, #schema_org_has_part, #schema_org_has_translation, #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_is_translation_of, #schema_org_references, #schema_org_related_identifier, #schema_org_reverse_related_identifier
Methods included from Readers::RisReader
Methods included from Readers::NpmReader
Methods included from Readers::DataciteJsonReader
Methods included from Readers::DataciteReader
#get_datacite, #get_titles, #read_datacite
Methods included from Readers::CrossrefReader
#crossref_alternate_identifiers, #crossref_date_published, #crossref_description, #crossref_funding_reference, #crossref_has_translation, #crossref_is_part_of, #crossref_is_translation_of, #crossref_license, #crossref_people, #crossref_references, #get_crossref, #read_crossref
Methods included from Readers::CrossciteReader
Methods included from Readers::CodemetaReader
Methods included from Readers::CiteprocReader
Methods included from Readers::BibtexReader
Methods included from DataciteUtils
#datacite_errors, #datacite_xml, #insert_alternate_identifiers, #insert_contributors, #insert_creators, #insert_dates, #insert_descriptions, #insert_formats, #insert_funding_references, #insert_geo_locations, #insert_identifier, #insert_language, #insert_person, #insert_publication_year, #insert_publisher, #insert_related_identifiers, #insert_related_items, #insert_resource_type, #insert_rights_list, #insert_sizes, #insert_subjects, #insert_titles, #insert_version, #insert_work, #root_attributes
Methods included from AuthorUtils
#authors_as_string, #cleanup_author, #get_affiliations, #get_authors, #get_one_author, #is_personal_name?, #name_exists?
Methods included from DoiUtils
#doi_api_url, #doi_as_url, #doi_from_url, #doi_resolver, #get_doi_ra, #normalize_doi, #validate_doi, #validate_funder_doi, #validate_prefix
Constructor Details
#initialize(options = {}) ⇒ Metadata
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/bolognese/metadata.rb', line 19 def initialize(={}) .symbolize_keys! id = normalize_id([:input], ) ra = nil if id.present? @from = [:from] || find_from_format(id: id) # mEDRA, KISTI, JaLC and OP DOIs are found in the Crossref index if @from == "medra" ra = "mEDRA" elsif @from == "kisti" ra = "KISTI" elsif @from == "jalc" ra = "JaLC" elsif @from == "op" ra = "OP" end # generate name for method to call dynamically hsh = @from.present? ? send("get_" + @from, id: id, sandbox: [:sandbox]) : {} string = hsh.fetch("string", nil) elsif [:input].present? && File.exist?([:input]) filename = File.basename([:input]) ext = File.extname([:input]) if %w(.bib .ris .xml .json).include?(ext) hsh = { "url" => [:url], "state" => [:state], "date_registered" => [:date_registered], "date_updated" => [:date_updated], "provider_id" => [:provider_id], "client_id" => [:client_id], "content_url" => [:content_url] } string = IO.read([:input]) @from = [:from] || find_from_format(string: string, filename: filename, ext: ext) else $stderr.puts "File type #{ext} not supported" exit 1 end else hsh = { "url" => [:url], "state" => [:state], "date_registered" => [:date_registered], "date_updated" => [:date_updated], "provider_id" => [:provider_id], "client_id" => [:client_id], "content_url" => [:content_url], "creators" => [:creators], "contributors" => [:contributors], "titles" => [:titles], "publisher" => [:publisher], "publication_year" => [:publication_year] } string = [:input] @from = [:from] || find_from_format(string: string) end # make sure input is encoded as utf8 string = string.force_encoding("UTF-8") if string.present? @string = string # input options for citation formatting @style = [:style] @locale = [:locale] @sandbox = [:sandbox] # options that come from the datacite database @url = hsh.to_h["url"].presence || [: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 # set attributes directly = .slice( :creators, :contributors, :titles, :types, :identifiers, :container, :publisher, :funding_references, :dates, :publication_year, :descriptions, :rights_list, :version_info, :subjects, :language, :geo_locations, :related_identifiers, :related_items, :formats, :sizes ).compact @regenerate = [:regenerate] || .present? # generate name for method to call dynamically opts = { string: string, sandbox: [:sandbox], doi: [:doi], id: id, ra: ra }.merge() = @from.present? ? send("read_" + @from, **opts) : {} end |
Instance Attribute Details
#agency ⇒ Object
234 235 236 |
# File 'lib/bolognese/metadata.rb', line 234 def agency @agency ||= .fetch("agency", nil) end |
#client_id ⇒ Object
139 140 141 |
# File 'lib/bolognese/metadata.rb', line 139 def client_id @client_id ||= .fetch("client_id", nil) end |
#container ⇒ Object
208 209 210 211 212 |
# File 'lib/bolognese/metadata.rb', line 208 def container @container ||= begin generate_container(types, , , descriptions) || .fetch("container", nil) end end |
#content_url ⇒ Object
230 231 232 |
# File 'lib/bolognese/metadata.rb', line 230 def content_url @content_url ||= .fetch("content_url", nil) end |
#contributor=(value) ⇒ Object (writeonly)
Sets the attribute contributor
12 13 14 |
# File 'lib/bolognese/metadata.rb', line 12 def contributor=(value) @contributor = value end |
#contributors ⇒ Object
258 259 260 |
# File 'lib/bolognese/metadata.rb', line 258 def contributors @contributors ||= .fetch("contributors", nil) end |
#creators ⇒ Object
254 255 256 |
# File 'lib/bolognese/metadata.rb', line 254 def creators @creators ||= .fetch("creators", nil) end |
#date_registered ⇒ Object
242 243 244 |
# File 'lib/bolognese/metadata.rb', line 242 def date_registered @date_registered ||= .fetch("date_registered", nil) end |
#dates ⇒ Object
218 219 220 |
# File 'lib/bolognese/metadata.rb', line 218 def dates @dates ||= .fetch("dates", nil) end |
#descriptions ⇒ Object
156 157 158 |
# File 'lib/bolognese/metadata.rb', line 156 def descriptions @descriptions ||= .fetch("descriptions", nil) end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
11 12 13 |
# File 'lib/bolognese/metadata.rb', line 11 def doc @doc end |
#doi ⇒ Object
131 132 133 |
# File 'lib/bolognese/metadata.rb', line 131 def doi @doi ||= .fetch("doi", nil) end |
#format=(value) ⇒ Object (writeonly)
Sets the attribute format
12 13 14 |
# File 'lib/bolognese/metadata.rb', line 12 def format=(value) @format = value end |
#formats ⇒ Object
176 177 178 |
# File 'lib/bolognese/metadata.rb', line 176 def formats @formats ||= .fetch("formats", nil) end |
#from ⇒ Object
Returns the value of attribute from.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def from @from end |
#funding_references ⇒ Object
184 185 186 |
# File 'lib/bolognese/metadata.rb', line 184 def funding_references @funding_references ||= .fetch("funding_references", nil) end |
#geo_locations ⇒ Object
214 215 216 |
# File 'lib/bolognese/metadata.rb', line 214 def geo_locations @geo_locations ||= .fetch("geo_locations", nil) end |
#id ⇒ Object
127 128 129 |
# File 'lib/bolognese/metadata.rb', line 127 def id @id ||= .fetch("id", nil) end |
#identifiers ⇒ Object
226 227 228 |
# File 'lib/bolognese/metadata.rb', line 226 def identifiers @identifiers ||= .fetch("identifiers", nil) end |
#issue ⇒ Object
Returns the value of attribute issue.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def issue @issue end |
#language ⇒ Object
168 169 170 |
# File 'lib/bolognese/metadata.rb', line 168 def language @language ||= .fetch("language", nil) end |
#locale=(value) ⇒ Object (writeonly)
Sets the attribute locale
12 13 14 |
# File 'lib/bolognese/metadata.rb', line 12 def locale=(value) @locale = value end |
#meta ⇒ Object
Returns the value of attribute meta.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def end |
#page_end ⇒ Object (readonly)
Returns the value of attribute page_end.
11 12 13 |
# File 'lib/bolognese/metadata.rb', line 11 def page_end @page_end end |
#page_start ⇒ Object (readonly)
Returns the value of attribute page_start.
11 12 13 |
# File 'lib/bolognese/metadata.rb', line 11 def page_start @page_start end |
#provider_id ⇒ Object
135 136 137 |
# File 'lib/bolognese/metadata.rb', line 135 def provider_id @provider_id ||= .fetch("provider_id", nil) end |
#publication_year ⇒ Object
204 205 206 |
# File 'lib/bolognese/metadata.rb', line 204 def publication_year @publication_year ||= .fetch("publication_year", nil) end |
#publisher ⇒ Object
222 223 224 |
# File 'lib/bolognese/metadata.rb', line 222 def publisher @publisher ||= normalize_publisher(["publisher"]) if .fetch("publisher", nil).present? end |
#regenerate ⇒ Object
Returns the value of attribute regenerate.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def regenerate @regenerate end |
#related_identifiers ⇒ Object
188 189 190 |
# File 'lib/bolognese/metadata.rb', line 188 def ||= .fetch("related_identifiers", nil) end |
#related_items ⇒ Object
192 193 194 |
# File 'lib/bolognese/metadata.rb', line 192 def ||= .fetch("related_items", nil) end |
#rights_list ⇒ Object
160 161 162 |
# File 'lib/bolognese/metadata.rb', line 160 def rights_list @rights_list ||= .fetch("rights_list", nil) end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def sandbox @sandbox end |
#schema_version ⇒ Object
180 181 182 |
# File 'lib/bolognese/metadata.rb', line 180 def schema_version @schema_version ||= .fetch("schema_version", nil) end |
#show_errors ⇒ Object
Returns the value of attribute show_errors.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def show_errors @show_errors end |
#sizes ⇒ Object
172 173 174 |
# File 'lib/bolognese/metadata.rb', line 172 def sizes @sizes ||= .fetch("sizes", nil) end |
#state ⇒ Object
238 239 240 |
# File 'lib/bolognese/metadata.rb', line 238 def state @state ||= .fetch("state", nil) end |
#string ⇒ Object
Returns the value of attribute string.
10 11 12 |
# File 'lib/bolognese/metadata.rb', line 10 def string @string end |
#style=(value) ⇒ Object (writeonly)
Sets the attribute style
12 13 14 |
# File 'lib/bolognese/metadata.rb', line 12 def style=(value) @style = value end |
#subjects ⇒ Object
164 165 166 |
# File 'lib/bolognese/metadata.rb', line 164 def subjects @subjects ||= .fetch("subjects", nil) end |
#titles ⇒ Object
250 251 252 |
# File 'lib/bolognese/metadata.rb', line 250 def titles @titles ||= .fetch("titles", nil) end |
#types ⇒ Object
246 247 248 |
# File 'lib/bolognese/metadata.rb', line 246 def types @types ||= .fetch("types", nil) end |
#url ⇒ Object
196 197 198 |
# File 'lib/bolognese/metadata.rb', line 196 def url @url ||= .fetch("url", nil) end |
#version_info ⇒ Object
200 201 202 |
# File 'lib/bolognese/metadata.rb', line 200 def version_info @version_info ||= .fetch("version_info", nil) || .fetch("version", nil) end |
#volume=(value) ⇒ Object (writeonly)
Sets the attribute volume
12 13 14 |
# File 'lib/bolognese/metadata.rb', line 12 def volume=(value) @volume = value end |
Instance Method Details
#errors ⇒ Object
validate against DataCite schema, unless there are already errors in the reader
152 153 154 |
# File 'lib/bolognese/metadata.rb', line 152 def errors .fetch("errors", nil) || datacite_errors(xml: datacite, schema_version: schema_version) end |
#exists? ⇒ Boolean
143 144 145 |
# File 'lib/bolognese/metadata.rb', line 143 def exists? (@state || .fetch("state", nil)) != "not_found" end |
#valid? ⇒ Boolean
147 148 149 |
# File 'lib/bolognese/metadata.rb', line 147 def valid? exists? && errors.nil? end |