Module: Commonmeta::MetadataUtils
- Includes:
- AuthorUtils, CrossrefUtils, DoiUtils, Readers::BibtexReader, Readers::CffReader, Readers::CodemetaReader, Readers::CrossrefReader, Readers::CrossrefXmlReader, Readers::CslReader, Readers::DataciteReader, Readers::JsonPostReader, Readers::NpmReader, Readers::RisReader, Readers::SchemaOrgReader, SchemaUtils, Utils, Writers::BibtexWriter, Writers::CffWriter, Writers::CitationWriter, Writers::CodemetaWriter, Writers::CrossrefXmlWriter, Writers::CslWriter, Writers::CsvWriter, Writers::DataciteWriter, Writers::JatsWriter, Writers::RdfXmlWriter, Writers::RisWriter, Writers::SchemaOrgWriter, Writers::TurtleWriter
- Included in:
- Metadata
- Defined in:
- lib/commonmeta/metadata_utils.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
-
#name_detector ⇒ Object
readonly
recognize given name.
-
#reverse ⇒ Object
readonly
Returns the value of attribute reverse.
Instance Method Summary collapse
- #container_title ⇒ Object
- #csl_hsh ⇒ Object
- #graph ⇒ Object
- #locale ⇒ Object
- #raw ⇒ Object
- #should_passthru ⇒ Object
- #style ⇒ Object
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::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::JsonPostReader
#get_json_post, #read_json_post
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, #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_post, #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_dates_from_date, #get_datetime_from_iso8601, #get_datetime_from_time, #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, #jsonlint, #map_hash_keys, #name_to_fos, #name_to_spdx, #normalize_cc_url, #normalize_id, #normalize_issn, #normalize_licenses, #normalize_orcid, #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, #validate_orcid, #validate_orcid_scheme, #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_alternate_identifiers, #insert_crossref_creators, #insert_crossref_issn, #insert_crossref_language, #insert_crossref_license, #insert_crossref_person, #insert_crossref_publication_date, #insert_crossref_subjects, #insert_crossref_titles, #insert_crossref_work, #insert_doi_data, #insert_group_title, #insert_institution, #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?
Instance Attribute Details
#name_detector ⇒ Object (readonly)
recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer
101 102 103 |
# File 'lib/commonmeta/metadata_utils.rb', line 101 def name_detector @name_detector end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse.
69 70 71 |
# File 'lib/commonmeta/metadata_utils.rb', line 69 def reverse @reverse end |
Instance Method Details
#container_title ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/commonmeta/metadata_utils.rb', line 92 def container_title if container.present? container['title'] elsif type == 'Article' publisher['name'] end end |
#csl_hsh ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/commonmeta/metadata_utils.rb', line 134 def csl_hsh page = if container.to_h['firstPage'].present? [container['firstPage'], container['lastPage']].compact.join('-') end = if Array.wrap(creators).size == 1 && Array.wrap(creators).first.fetch('name', nil) == ':(unav)' nil else to_csl(creators) end type_ = if type == 'Software' && version.present? 'book' else CM_TO_CSL_TRANSLATIONS.fetch(type, 'document') end categories = Array.wrap(subjects).map do |k| parse_attributes(k, content: 'subject', first: true) end.presence { 'type' => type_, 'id' => id, 'categories' => categories, 'language' => language, 'author' => , 'contributor' => to_csl(contributors), 'issued' => get_date_parts(date['published']), 'submitted' => date['submitted'] ? get_date_parts(date['submitted']) : nil, 'abstract' => parse_attributes(descriptions, content: 'description', first: true), 'container-title' => container_title, 'DOI' => doi_from_url(id), 'volume' => container.to_h['volume'], 'issue' => container.to_h['issue'], 'page' => page, 'publisher' => publisher['name'], 'title' => parse_attributes(titles, content: 'title', first: true), 'URL' => url, 'copyright' => license.to_h['id'], 'version' => version }.compact.symbolize_keys end |
#graph ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/commonmeta/metadata_utils.rb', line 122 def graph # preload schema_org context JSON::LD::Context.add_preloaded( 'http://schema.org/', JSON::LD::Context.new.parse('resources/schema_org/jsonldcontext.json') ) RDF::Graph.new << JSON::LD::API.toRdf(schema_hsh) rescue NameError nil end |
#locale ⇒ Object
182 183 184 |
# File 'lib/commonmeta/metadata_utils.rb', line 182 def locale @locale ||= 'en-US' end |
#raw ⇒ Object
81 82 83 84 85 86 |
# File 'lib/commonmeta/metadata_utils.rb', line 81 def raw r = string.present? ? string.strip : nil return r unless from == 'crossref_xml' && r.present? r end |
#should_passthru ⇒ Object
88 89 90 |
# File 'lib/commonmeta/metadata_utils.rb', line 88 def should_passthru (from == 'crossref_xml') && regenerate.blank? && raw.present? end |
#style ⇒ Object
178 179 180 |
# File 'lib/commonmeta/metadata_utils.rb', line 178 def style @style ||= 'apa' end |