Class: Commonmeta::Metadata
- Inherits:
-
Object
- Object
- Commonmeta::Metadata
- Includes:
- MetadataUtils
- Defined in:
- lib/commonmeta/metadata.rb
Constant Summary
Constants included from Readers::SchemaOrgReader
Readers::SchemaOrgReader::SO_TO_DC_RELATION_TYPES, Readers::SchemaOrgReader::SO_TO_DC_REVERSE_RELATION_TYPES
Constants included from Utils
Utils::BIB_TO_CM_TRANSLATIONS, Utils::CM_TO_BIB_TRANSLATIONS, Utils::CM_TO_CR_TRANSLATIONS, Utils::CM_TO_CSL_TRANSLATIONS, Utils::CM_TO_DC_TRANSLATIONS, Utils::CM_TO_JATS_TRANSLATIONS, Utils::CM_TO_RIS_TRANSLATIONS, Utils::CM_TO_SO_TRANSLATIONS, Utils::CR_TO_CM_TRANSLATIONS, Utils::CSL_TO_CM_TRANSLATIONS, Utils::DC_TO_CM_TRANSLATIONS, Utils::NORMALIZED_LICENSES, Utils::RIS_TO_CM_TRANSLATIONS, Utils::SO_TO_CM_TRANSLATIONS, Utils::UNKNOWN_INFORMATION
Constants included from SchemaUtils
Instance Attribute Summary collapse
- #additional_type ⇒ Object
- #alternate_identifiers ⇒ Object
- #client_id ⇒ Object
- #container ⇒ Object
- #content_url ⇒ Object
-
#contributor ⇒ Object
writeonly
Sets the attribute contributor.
- #contributors ⇒ Object
- #creators ⇒ Object
- #date ⇒ Object
-
#depositor ⇒ Object
Returns the value of attribute depositor.
- #descriptions ⇒ Object
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
- #doi ⇒ Object
-
#email ⇒ Object
Returns the value of attribute email.
-
#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
-
#issue ⇒ Object
Returns the value of attribute issue.
- #language ⇒ Object
- #license ⇒ 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 ⇒ Object
- #provider_id ⇒ Object
- #publisher ⇒ Object
- #references ⇒ Object
-
#regenerate ⇒ Object
Returns the value of attribute regenerate.
-
#registrant ⇒ Object
Returns the value of attribute registrant.
- #related_identifiers ⇒ Object
- #related_items ⇒ 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
- #type ⇒ Object
- #url ⇒ Object
- #version ⇒ Object
-
#volume ⇒ Object
writeonly
Sets the attribute volume.
Attributes included from MetadataUtils
Instance Method Summary collapse
-
#errors ⇒ Object
Catch errors in the reader Then validate against JSON schema for Commonmeta.
- #exists? ⇒ Boolean
-
#initialize(options = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #valid? ⇒ Boolean
Methods included from MetadataUtils
#container_title, #csl_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
#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::DataciteWriter
#datacite, #datacite_contributor, #datacite_reference
Methods included from Writers::CsvWriter
Methods included from Writers::CslWriter
Methods included from Writers::CrossrefXmlWriter
Methods included from Writers::CodemetaWriter
Methods included from Writers::CffWriter
#cff, #write_cff_creators, #write_cff_reference
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_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_reference, #schema_org_references
Methods included from Readers::RisReader
Methods included from Readers::NpmReader
Methods included from Readers::JsonFeedReader
#get_doi_prefix_by_blog_id, #get_doi_prefix_by_json_feed_item_id, #get_json_feed_by_blog, #get_json_feed_item, #get_json_feed_not_indexed, #get_json_feed_unregistered, #get_references, #get_related_identifiers, #read_json_feed_item
Methods included from Readers::DataciteReader
#format_contributor, #get_datacite, #get_datacite_reference, #read_datacite
Methods included from Readers::CslReader
Methods included from Readers::CrossrefXmlReader
#crossref_alternate_identifiers, #crossref_date_published, #crossref_description, #crossref_funding_reference, #crossref_license, #crossref_people, #crossref_references, #get_crossref_xml, #read_crossref_xml
Methods included from Readers::CrossrefReader
#get_crossref, #get_reference, #read_crossref
Methods included from Readers::CodemetaReader
Methods included from Readers::CffReader
#cff_creators, #get_cff, #get_cff_reference, #read_cff
Methods included from Readers::BibtexReader
Methods included from Utils
#decode_container_id, #decode_doi, #encode_container_id, #encode_doi, #encode_doi_for_id, #find_from_format, #find_from_format_by_ext, #find_from_format_by_filename, #find_from_format_by_id, #find_from_format_by_string, #from_csl, #from_datacite, #from_json_feed, #from_schema_org, #generate_ghost_token, #get_contributor, #get_date, #get_date_from_date_parts, #get_date_from_parts, #get_date_from_unix_timestamp, #get_date_parts, #get_date_parts_from_parts, #get_dates_from_date, #get_datetime_from_iso8601, #get_datetime_from_time, #get_datetime_from_unix_timestamp, #get_identifier, #get_identifier_type, #get_iso8601_date, #get_link, #get_series_information, #get_year_month, #get_year_month_day, #github_as_cff_url, #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, #json_feed_by_blog_url, #json_feed_item_by_id_url, #json_feed_not_indexed_url, #json_feed_unregistered_url, #jsonlint, #map_hash_keys, #name_to_fos, #name_to_spdx, #normalize_cc_url, #normalize_id, #normalize_issn, #normalize_licenses, #normalize_orcid, #normalize_ror, #normalize_url, #orcid_as_url, #orcid_from_url, #parse_attributes, #rogue_scholar_api_url, #sanitize, #spdx_to_hsh, #strip_milliseconds, #to_csl, #to_datacite, #to_identifier, #to_ris, #to_schema_org, #to_schema_org_citation, #to_schema_org_container, #to_schema_org_funder, #to_schema_org_identifiers, #to_schema_org_relation, #to_schema_org_spatial_coverage, #update_ghost_post_via_api, #validate_email, #validate_orcid, #validate_orcid_scheme, #validate_ror, #validate_url
Methods included from SchemaUtils
Methods included from DoiUtils
#crossref_api_url, #datacite_api_url, #doi_as_url, #doi_from_url, #doi_resolver, #get_crossref_member, #get_doi_ra, #normalize_doi, #validate_doi, #validate_funder_doi, #validate_prefix
Methods included from CrossrefUtils
#crossref_errors, #crossref_root_attributes, #insert_citation_list, #insert_crossref_abstract, #insert_crossref_access_indicators, #insert_crossref_anonymous, #insert_crossref_creators, #insert_crossref_issn, #insert_crossref_language, #insert_crossref_license, #insert_crossref_person, #insert_crossref_publication_date, #insert_crossref_relations, #insert_crossref_subjects, #insert_crossref_titles, #insert_crossref_work, #insert_doi_data, #insert_group_title, #insert_institution, #insert_item_number, #insert_journal, #insert_posted_content, #insert_posted_date, #write_crossref_xml
Methods included from AuthorUtils
#author_name_identifiers, #authors_as_string, #cleanup_author, #get_affiliations, #get_authors, #get_one_author, #is_personal_name?, #name_exists?
Constructor Details
#initialize(options = {}) ⇒ Metadata
Returns a new instance of Metadata.
15 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 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 126 127 |
# File 'lib/commonmeta/metadata.rb', line 15 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 case @from when 'medra' ra = 'mEDRA' when 'kisti' ra = 'KISTI' when 'jalc' ra = 'JaLC' when 'op' ra = 'OP' end # generate name for method to call dynamically hsh = @from.present? ? send("get_#{@from}", id: id, **) : {} 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 .cff].include?(ext) hsh = { 'url' => [:url], 'state' => [:state], 'provider_id' => [:provider_id], 'client_id' => [:client_id], 'content_url' => [:content_url] } string = File.read([:input]) @from = [:from] || find_from_format(string: string, ext: ext) else warn "File type #{ext} not supported" exit 1 end else hsh = { 'url' => [:url], 'state' => [:state], 'provider_id' => [:provider_id], 'client_id' => [:client_id], 'content_url' => [:content_url], 'creators' => [:creators], 'contributors' => [:contributors], 'titles' => [:titles], 'publisher' => [:publisher] } string = [:input] @from = [:from] || find_from_format(string: string) end # make sure input is encoded as utf8 if string.present? && string.is_a?(String) dup_string = string.dup.force_encoding('UTF-8').encode! end @string = dup_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 @provider_id = hsh.to_h['provider_id'].presence @client_id = hsh.to_h['client_id'].presence @content_url = hsh.to_h['content_url'].presence # options that come from the cli, needed # for crossref doi registration @depositor = [:depositor] @email = [:email] @registrant = [:registrant] # set attributes directly = .slice( :creators, :contributors, :titles, :type, :additional_type, :container, :publisher, :funding_references, :date, :descriptions, :rights_list, :version, :subjects, :language, :geo_locations, :references, :alternate_identifiers, :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() @meta = @from.present? ? send("read_#{@from}", **opts) : {} end |
Instance Attribute Details
#additional_type ⇒ Object
247 248 249 |
# File 'lib/commonmeta/metadata.rb', line 247 def additional_type @additional_type ||= .fetch('additional_type', nil) end |
#alternate_identifiers ⇒ Object
227 228 229 |
# File 'lib/commonmeta/metadata.rb', line 227 def alternate_identifiers @alternate_identifiers ||= .fetch('alternate_identifiers', nil) end |
#client_id ⇒ Object
141 142 143 |
# File 'lib/commonmeta/metadata.rb', line 141 def client_id @client_id ||= .fetch('client_id', nil) end |
#container ⇒ Object
211 212 213 |
# File 'lib/commonmeta/metadata.rb', line 211 def container @container ||= .fetch('container', nil) end |
#content_url ⇒ Object
231 232 233 |
# File 'lib/commonmeta/metadata.rb', line 231 def content_url @content_url ||= .fetch('content_url', nil) end |
#contributor=(value) ⇒ Object (writeonly)
Sets the attribute contributor
12 13 14 |
# File 'lib/commonmeta/metadata.rb', line 12 def contributor=(value) @contributor = value end |
#contributors ⇒ Object
259 260 261 |
# File 'lib/commonmeta/metadata.rb', line 259 def contributors @contributors ||= .fetch('contributors', nil) end |
#creators ⇒ Object
255 256 257 |
# File 'lib/commonmeta/metadata.rb', line 255 def creators @creators ||= .fetch('creators', nil) end |
#date ⇒ Object
219 220 221 |
# File 'lib/commonmeta/metadata.rb', line 219 def date @date ||= .fetch('date', nil) end |
#depositor ⇒ Object
Returns the value of attribute depositor.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def depositor @depositor end |
#descriptions ⇒ Object
159 160 161 |
# File 'lib/commonmeta/metadata.rb', line 159 def descriptions @descriptions ||= .fetch('descriptions', nil) end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
11 12 13 |
# File 'lib/commonmeta/metadata.rb', line 11 def doc @doc end |
#doi ⇒ Object
133 134 135 |
# File 'lib/commonmeta/metadata.rb', line 133 def doi @doi ||= .fetch('doi', nil) end |
#email ⇒ Object
Returns the value of attribute email.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def email @email end |
#format=(value) ⇒ Object (writeonly)
Sets the attribute format
12 13 14 |
# File 'lib/commonmeta/metadata.rb', line 12 def format=(value) @format = value end |
#formats ⇒ Object
179 180 181 |
# File 'lib/commonmeta/metadata.rb', line 179 def formats @formats ||= .fetch('formats', nil) end |
#from ⇒ Object
Returns the value of attribute from.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def from @from end |
#funding_references ⇒ Object
187 188 189 |
# File 'lib/commonmeta/metadata.rb', line 187 def funding_references @funding_references ||= .fetch('funding_references', nil) end |
#geo_locations ⇒ Object
215 216 217 |
# File 'lib/commonmeta/metadata.rb', line 215 def geo_locations @geo_locations ||= .fetch('geo_locations', nil) end |
#id ⇒ Object
129 130 131 |
# File 'lib/commonmeta/metadata.rb', line 129 def id @id ||= .fetch('id', nil) end |
#issue ⇒ Object
Returns the value of attribute issue.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def issue @issue end |
#language ⇒ Object
171 172 173 |
# File 'lib/commonmeta/metadata.rb', line 171 def language @language ||= .fetch('language', nil) end |
#license ⇒ Object
163 164 165 |
# File 'lib/commonmeta/metadata.rb', line 163 def license @license ||= .fetch('license', nil) end |
#locale=(value) ⇒ Object (writeonly)
Sets the attribute locale
12 13 14 |
# File 'lib/commonmeta/metadata.rb', line 12 def locale=(value) @locale = value end |
#meta ⇒ Object
Returns the value of attribute meta.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def @meta end |
#page_end ⇒ Object (readonly)
Returns the value of attribute page_end.
11 12 13 |
# File 'lib/commonmeta/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/commonmeta/metadata.rb', line 11 def page_start @page_start end |
#provider ⇒ Object
235 236 237 |
# File 'lib/commonmeta/metadata.rb', line 235 def provider @provider ||= .fetch('provider', nil) end |
#provider_id ⇒ Object
137 138 139 |
# File 'lib/commonmeta/metadata.rb', line 137 def provider_id @provider_id ||= .fetch('provider_id', nil) end |
#publisher ⇒ Object
223 224 225 |
# File 'lib/commonmeta/metadata.rb', line 223 def publisher @publisher ||= .fetch('publisher', nil) end |
#references ⇒ Object
191 192 193 |
# File 'lib/commonmeta/metadata.rb', line 191 def references @references ||= .fetch('references', nil) end |
#regenerate ⇒ Object
Returns the value of attribute regenerate.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def regenerate @regenerate end |
#registrant ⇒ Object
Returns the value of attribute registrant.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def registrant @registrant end |
#related_identifiers ⇒ Object
195 196 197 |
# File 'lib/commonmeta/metadata.rb', line 195 def @related_identifiers ||= .fetch('related_identifiers', nil) end |
#related_items ⇒ Object
199 200 201 |
# File 'lib/commonmeta/metadata.rb', line 199 def @related_items ||= .fetch('related_items', nil) end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def sandbox @sandbox end |
#schema_version ⇒ Object
183 184 185 |
# File 'lib/commonmeta/metadata.rb', line 183 def schema_version @schema_version ||= .fetch('schema_version', nil) end |
#show_errors ⇒ Object
Returns the value of attribute show_errors.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def show_errors @show_errors end |
#sizes ⇒ Object
175 176 177 |
# File 'lib/commonmeta/metadata.rb', line 175 def sizes @sizes ||= .fetch('sizes', nil) end |
#state ⇒ Object
239 240 241 |
# File 'lib/commonmeta/metadata.rb', line 239 def state @state ||= .fetch('state', nil) end |
#string ⇒ Object
Returns the value of attribute string.
9 10 11 |
# File 'lib/commonmeta/metadata.rb', line 9 def string @string end |
#style=(value) ⇒ Object (writeonly)
Sets the attribute style
12 13 14 |
# File 'lib/commonmeta/metadata.rb', line 12 def style=(value) @style = value end |
#subjects ⇒ Object
167 168 169 |
# File 'lib/commonmeta/metadata.rb', line 167 def subjects @subjects ||= .fetch('subjects', nil) end |
#titles ⇒ Object
251 252 253 |
# File 'lib/commonmeta/metadata.rb', line 251 def titles @titles ||= .fetch('titles', nil) end |
#type ⇒ Object
243 244 245 |
# File 'lib/commonmeta/metadata.rb', line 243 def type @type ||= .fetch('type', nil) end |
#url ⇒ Object
203 204 205 |
# File 'lib/commonmeta/metadata.rb', line 203 def url @url ||= .fetch('url', nil) end |
#version ⇒ Object
207 208 209 |
# File 'lib/commonmeta/metadata.rb', line 207 def version @version ||= .fetch('version', nil) end |
#volume=(value) ⇒ Object (writeonly)
Sets the attribute volume
12 13 14 |
# File 'lib/commonmeta/metadata.rb', line 12 def volume=(value) @volume = value end |
Instance Method Details
#errors ⇒ Object
Catch errors in the reader Then validate against JSON schema for Commonmeta
155 156 157 |
# File 'lib/commonmeta/metadata.rb', line 155 def errors .fetch('errors', nil) || json_schema_errors end |
#exists? ⇒ Boolean
145 146 147 |
# File 'lib/commonmeta/metadata.rb', line 145 def exists? (@state || .fetch('state', nil)) != 'not_found' end |
#valid? ⇒ Boolean
149 150 151 |
# File 'lib/commonmeta/metadata.rb', line 149 def valid? exists? && errors.nil? end |