Class: Bolognese::Metadata
- Inherits:
-
Object
- Object
- Bolognese::Metadata
- Includes:
- MetadataUtils
- Defined in:
- lib/bolognese/metadata.rb
Constant Summary
Constants included from Readers::SchemaOrgReader
Readers::SchemaOrgReader::SO_TO_DC_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::CONTACT_EMAIL
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 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
Attributes included from MetadataUtils
#additional_type, #alternate_identifier, #author, #b_url, #b_version, #bibtex_type, #citeproc_type, #cites, #compiles, #content_format, #content_size, #content_url, #continues, #contributor, #date_accepted, #date_available, #date_collected, #date_copyrighted, #date_created, #date_modified, #date_published, #date_submitted, #date_updated, #date_valid, #description, #doc, #documents, #editor, #first_page, #format, #from, #funding, #has_metadata, #has_part, #identifier, #is_cited_by, #is_compiled_by, #is_continued_by, #is_derived_from, #is_documented_by, #is_metadata_for, #is_new_version_of, #is_original_form_of, #is_previous_version_of, #is_referenced_by, #is_reviewed_by, #is_source_of, #is_supplement_to, #is_supplemented_by, #is_variant_form_of, #issue, #journal, #keywords, #language, #last_page, #license, #locale, #meta, #name_detector, #page_end, #page_start, #publisher, #references, #regenerate, #related_identifier, #resource_type_general, #reverse, #reviews, #ris_type, #same_as, #sandbox, #schema_version, #service_provider, #spatial_coverage, #state, #string, #style, #title, #type, #volume
Instance Method Summary collapse
-
#errors ⇒ Object
validate against DataCite schema, unless there are already errors in the reader.
- #exists? ⇒ Boolean
-
#initialize(input: nil, from: nil, **options) ⇒ Metadata
constructor
A new instance of Metadata.
- #valid? ⇒ Boolean
Methods included from MetadataUtils
#container_title, #date_registered, #descriptions, #graph, #is_identical_to, #is_part_of, #publication_year, #raw, #related_identifier_hsh, #should_passthru
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::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_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
Methods included from Readers::RisReader
Methods included from Readers::DataciteJsonReader
Methods included from Readers::DataciteReader
#datacite_date, #datacite_funder_contributor, #datacite_funding_reference, #datacite_has_part, #datacite_is_identical_to, #datacite_is_new_version_of, #datacite_is_original_form_of, #datacite_is_part_of, #datacite_is_previous_version_of, #datacite_is_referenced_by, #datacite_is_reviewed_by, #datacite_is_supplement_to, #datacite_is_supplemented_by, #datacite_is_variant_form_of, #datacite_references, #datacite_related_identifier, #datacite_reviews, #get_datacite, #read_datacite
Methods included from Readers::CrossrefReader
#crossref_alternate_identifier, #crossref_date_published, #crossref_description, #crossref_funding_reference, #crossref_is_part_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 Utils
#find_from_format, #find_from_format_by_ext, #find_from_format_by_id, #find_from_format_by_string, #from_citeproc, #from_schema_org, #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_ris, #to_schema_org, #to_schema_org_container, #to_schema_org_identifier, #validate_orcid, #validate_orcid_scheme, #validate_url
Methods included from DataciteUtils
#datacite_errors, #datacite_xml, #insert_alternate_identifiers, #insert_contributors, #insert_creators, #insert_date, #insert_dates, #insert_descriptions, #insert_funding_reference, #insert_funding_references, #insert_identifier, #insert_person, #insert_publication_year, #insert_publisher, #insert_related_identifiers, #insert_resource_type, #insert_rights_list, #insert_subjects, #insert_title, #insert_titles, #insert_version, #insert_work, #rel_identifier, #res_type, #root_attributes
Methods included from AuthorUtils
#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
Returns a new instance of Metadata.
11 12 13 14 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 |
# File 'lib/bolognese/metadata.rb', line 11 def initialize(input: nil, from: nil, **) id = normalize_id(input, ) if id.present? @from = from || find_from_format(id: id) # 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) ext = File.extname(input) if %w(.bib .ris .xml .json).include?(ext) hsh = { "b_url" => [:b_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, ext: ext) else $stderr.puts "File type #{ext} not supported" exit 1 end else hsh = { "b_url" => [:b_url], "state" => [:state], "date_registered" => [:date_registered], "date_updated" => [:date_updated], "provider_id" => [:provider_id], "client_id" => [:client_id], "content_url" => [:content_url] } 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] @regenerate = [:regenerate] @sandbox = [:sandbox] # options that come from the datacite database @b_url = hsh.to_h["b_url"].presence || [:b_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 # generate name for method to call dynamically = @from.present? ? send("read_" + @from, string: string, sandbox: [:sandbox]) : {} @identifier = normalize_doi([:doi] || input, ) || .fetch("id", nil) || .fetch("identifier", nil) end |
Instance Attribute Details
#client_id ⇒ Object
85 86 87 |
# File 'lib/bolognese/metadata.rb', line 85 def client_id @client_id ||= .fetch("client_id", nil) end |
#doi ⇒ Object
77 78 79 |
# File 'lib/bolognese/metadata.rb', line 77 def doi @doi ||= @identifier.present? ? doi_from_url(@identifier) : .fetch("doi", nil) end |
#id ⇒ Object
73 74 75 |
# File 'lib/bolognese/metadata.rb', line 73 def id @id ||= .fetch("id", nil) end |
#provider_id ⇒ Object
81 82 83 |
# File 'lib/bolognese/metadata.rb', line 81 def provider_id @provider_id ||= .fetch("provider_id", nil) end |
Instance Method Details
#errors ⇒ Object
validate against DataCite schema, unless there are already errors in the reader
98 99 100 |
# File 'lib/bolognese/metadata.rb', line 98 def errors .fetch("errors", nil) || datacite_errors(xml: datacite, schema_version: schema_version) end |
#exists? ⇒ Boolean
89 90 91 |
# File 'lib/bolognese/metadata.rb', line 89 def exists? (@state || .fetch("state", "not_found")) != "not_found" end |
#valid? ⇒ Boolean
93 94 95 |
# File 'lib/bolognese/metadata.rb', line 93 def valid? exists? && errors.nil? end |