Class: Bolognese::Metadata

Direct Known Subclasses

Orcid

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, Readers::CrossrefReader::CR_TO_BIB_TRANSLATIONS, Readers::CrossrefReader::CR_TO_SO_TRANSLATIONS

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::CR_TO_CP_TRANSLATIONS, Utils::CR_TO_RIS_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_RIS_TRANSLATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Writers::TurtleWriter

#turtle

Methods included from Writers::SchemaOrgWriter

#schema_hsh, #schema_org

Methods included from Writers::RisWriter

#ris

Methods included from Writers::RdfXmlWriter

#rdf_xml

Methods included from Writers::DataciteJsonWriter

#datacite_json

Methods included from Writers::DataciteWriter

#datacite

Methods included from Writers::CrossrefWriter

#crossref

Methods included from Writers::CrossciteWriter

#crosscite

Methods included from Writers::CodemetaWriter

#codemeta

Methods included from Writers::CiteprocWriter

#citeproc

Methods included from Writers::BibtexWriter

#bibtex

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

#read_ris, #ris_meta

Methods included from Readers::DataciteJsonReader

#read_datacite_json

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_name, #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

#read_crosscite

Methods included from Readers::CodemetaReader

#get_codemeta, #read_codemeta

Methods included from Readers::CiteprocReader

#read_citeproc

Methods included from Readers::BibtexReader

#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_schema_org, #get_date_from_date_parts, #get_date_from_parts, #get_date_parts, #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, #validate_orcid, #validate_url

Methods included from DataciteUtils

#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, #resource_type, #root_attributes, #schema

Methods included from DateUtils

#get_date_from_parts, #get_date_parts, #get_date_parts_from_parts, #get_datetime_from_iso8601, #get_year_month, #get_year_month_day

Methods included from AuthorUtils

#authors_as_string, #cleanup_author, #get_authors, #get_name_identifier, #get_one_author, #is_personal_name?

Methods included from DoiUtils

#doi_as_url, #doi_from_url, #get_doi_ra, #normalize_doi, #validate_doi, #validate_prefix

Constructor Details

#initialize(input: nil, from: nil, regenerate: false) ⇒ Metadata

Returns a new instance of Metadata.



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
# File 'lib/bolognese/metadata.rb', line 75

def initialize(input: nil, from: nil, regenerate: false)
  id = normalize_id(input)

  if id.present?
    @from = from || find_from_format(id: id)

    # generate name for method to call dynamically
    string = @from.present? ? send("get_" + @from, id: id) : nil
  elsif File.exist?(input)
    ext = File.extname(input)
    if %w(.bib .ris .xml .json).include?(ext)
      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
    string = input
    @from = from || find_from_format(string: string)
  end

  # generate name for method to call dynamically
  @metadata = @from.present? ? send("read_" + @from, string: string) : {}
  @raw = string
  @should_passthru = (@from == "datacite") && !regenerate
end

Instance Attribute Details

#additional_typeObject (readonly)

Returns the value of attribute additional_type.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def additional_type
  @additional_type
end

#alternate_nameObject (readonly)

Returns the value of attribute alternate_name.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def alternate_name
  @alternate_name
end

#bibtex_typeObject (readonly)

Returns the value of attribute bibtex_type.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def bibtex_type
  @bibtex_type
end

#citationObject (readonly)

Returns the value of attribute citation.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def citation
  @citation
end

#citeproc_typeObject (readonly)

Returns the value of attribute citeproc_type.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def citeproc_type
  @citeproc_type
end

#citesObject (readonly)

Returns the value of attribute cites.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def cites
  @cites
end

#compilesObject (readonly)

Returns the value of attribute compiles.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def compiles
  @compiles
end

#content_sizeObject (readonly)

Returns the value of attribute content_size.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def content_size
  @content_size
end

#continuesObject (readonly)

Returns the value of attribute continues.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def continues
  @continues
end

#contributorObject (readonly)

Returns the value of attribute contributor.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def contributor
  @contributor
end

#datacite_errorsObject (readonly)

Returns the value of attribute datacite_errors.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def datacite_errors
  @datacite_errors
end

#date_acceptedObject (readonly)

Returns the value of attribute date_accepted.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_accepted
  @date_accepted
end

#date_availableObject (readonly)

Returns the value of attribute date_available.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_available
  @date_available
end

#date_collectedObject (readonly)

Returns the value of attribute date_collected.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_collected
  @date_collected
end

#date_copyrightedObject (readonly)

Returns the value of attribute date_copyrighted.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_copyrighted
  @date_copyrighted
end

#date_createdObject (readonly)

Returns the value of attribute date_created.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_created
  @date_created
end

#date_modifiedObject (readonly)

Returns the value of attribute date_modified.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_modified
  @date_modified
end

#date_submittedObject (readonly)

Returns the value of attribute date_submitted.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def 
  @date_submitted
end

#date_validObject (readonly)

Returns the value of attribute date_valid.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def date_valid
  @date_valid
end

#docObject (readonly)

Returns the value of attribute doc.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def doc
  @doc
end

#documentsObject (readonly)

Returns the value of attribute documents.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def documents
  @documents
end

#editorObject (readonly)

Returns the value of attribute editor.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def editor
  @editor
end

#errorsObject (readonly)

Returns the value of attribute errors.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def errors
  @errors
end

#formatObject (readonly)

Returns the value of attribute format.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def format
  @format
end

#fromObject (readonly)

Returns the value of attribute from.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def from
  @from
end

#fundingObject (readonly)

Returns the value of attribute funding.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def funding
  @funding
end

#has_metadataObject (readonly)

Returns the value of attribute has_metadata.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def 
  @has_metadata
end

#has_partObject (readonly)

Returns the value of attribute has_part.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def has_part
  @has_part
end

#idObject (readonly)

def errors

doc && doc.errors.map { |error| error.to_s }.unwrap

end



119
120
121
# File 'lib/bolognese/metadata.rb', line 119

def id
  @id
end

#is_cited_byObject (readonly)

Returns the value of attribute is_cited_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_cited_by
  @is_cited_by
end

#is_compiled_byObject (readonly)

Returns the value of attribute is_compiled_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_compiled_by
  @is_compiled_by
end

#is_continued_byObject (readonly)

Returns the value of attribute is_continued_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_continued_by
  @is_continued_by
end

#is_derived_fromObject (readonly)

Returns the value of attribute is_derived_from.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_derived_from
  @is_derived_from
end

#is_documented_byObject (readonly)

Returns the value of attribute is_documented_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_documented_by
  @is_documented_by
end

#is_metadata_forObject (readonly)

Returns the value of attribute is_metadata_for.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def 
  @is_metadata_for
end

#is_new_version_ofObject (readonly)

Returns the value of attribute is_new_version_of.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_new_version_of
  @is_new_version_of
end

#is_original_form_ofObject (readonly)

Returns the value of attribute is_original_form_of.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_original_form_of
  @is_original_form_of
end

#is_previous_version_ofObject (readonly)

Returns the value of attribute is_previous_version_of.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_previous_version_of
  @is_previous_version_of
end

#is_referenced_byObject (readonly)

Returns the value of attribute is_referenced_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_referenced_by
  @is_referenced_by
end

#is_reviewed_byObject (readonly)

Returns the value of attribute is_reviewed_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_reviewed_by
  @is_reviewed_by
end

#is_source_ofObject (readonly)

Returns the value of attribute is_source_of.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_source_of
  @is_source_of
end

#is_supplement_toObject (readonly)

Returns the value of attribute is_supplement_to.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_supplement_to
  @is_supplement_to
end

#is_supplemented_byObject (readonly)

Returns the value of attribute is_supplemented_by.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_supplemented_by
  @is_supplemented_by
end

#is_variant_form_ofObject (readonly)

Returns the value of attribute is_variant_form_of.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def is_variant_form_of
  @is_variant_form_of
end

#issueObject (readonly)

Returns the value of attribute issue.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def issue
  @issue
end

#journalObject (readonly)

Returns the value of attribute journal.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def journal
  @journal
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def keywords
  @keywords
end

#languageObject (readonly)

Returns the value of attribute language.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def language
  @language
end

#licenseObject (readonly)

Returns the value of attribute license.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def license
  @license
end

#metadataObject (readonly)

Returns the value of attribute metadata.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def 
  @metadata
end

#name_detectorObject (readonly)

recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer



317
318
319
# File 'lib/bolognese/metadata.rb', line 317

def name_detector
  @name_detector
end

#page_endObject (readonly)

Returns the value of attribute page_end.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def page_end
  @page_end
end

#page_startObject (readonly)

Returns the value of attribute page_start.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def page_start
  @page_start
end

#providerObject (readonly)

Returns the value of attribute provider.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def provider
  @provider
end

#publisherObject (readonly)

Returns the value of attribute publisher.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def publisher
  @publisher
end

#rawObject (readonly)

Returns the value of attribute raw.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def raw
  @raw
end

#referencesObject (readonly)

Returns the value of attribute references.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def references
  @references
end

Returns the value of attribute related_identifier.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def related_identifier
  @related_identifier
end

#reverseObject (readonly)

Returns the value of attribute reverse.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def reverse
  @reverse
end

#reviewsObject (readonly)

Returns the value of attribute reviews.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def reviews
  @reviews
end

#ris_typeObject (readonly)

Returns the value of attribute ris_type.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def ris_type
  @ris_type
end

#same_asObject (readonly)

Returns the value of attribute same_as.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def same_as
  @same_as
end

#schema_versionObject (readonly)

Returns the value of attribute schema_version.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def schema_version
  @schema_version
end

#should_passthruObject (readonly)

Returns the value of attribute should_passthru.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def should_passthru
  @should_passthru
end

#spatial_coverageObject (readonly)

Returns the value of attribute spatial_coverage.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def spatial_coverage
  @spatial_coverage
end

#urlObject (readonly)

Returns the value of attribute url.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def version
  @version
end

#volumeObject (readonly)

Returns the value of attribute volume.



60
61
62
# File 'lib/bolognese/metadata.rb', line 60

def volume
  @volume
end

Instance Method Details

#authorObject



163
164
165
# File 'lib/bolognese/metadata.rb', line 163

def author
  .fetch("author", nil)
end

#container_titleObject



325
326
327
# File 'lib/bolognese/metadata.rb', line 325

def container_title
  Array.wrap(is_part_of).length == 1 ? is_part_of.to_h.fetch("title", nil) : nil
end

#date_publishedObject



207
208
209
# File 'lib/bolognese/metadata.rb', line 207

def date_published
  .fetch("date_published", nil)
end

#descriptionObject



223
224
225
# File 'lib/bolognese/metadata.rb', line 223

def description
  .fetch("description", nil)
end

#descriptionsObject



329
330
331
# File 'lib/bolognese/metadata.rb', line 329

def descriptions
  Array.wrap(description)
end

#doiObject



147
148
149
# File 'lib/bolognese/metadata.rb', line 147

def doi
  .fetch("doi", nil)
end

#exists?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/bolognese/metadata.rb', line 103

def exists?
  .fetch("id", nil).present?
end

#graphObject



338
339
340
# File 'lib/bolognese/metadata.rb', line 338

def graph
  RDF::Graph.new << JSON::LD::API.toRdf(schema_hsh)
end

#is_identical_toObject



255
256
257
# File 'lib/bolognese/metadata.rb', line 255

def is_identical_to
  .fetch("is_identical_to", nil)
end

#is_part_ofObject



259
260
261
# File 'lib/bolognese/metadata.rb', line 259

def is_part_of
  .fetch("is_part_of", nil)
end

#paginationObject



219
220
221
# File 'lib/bolognese/metadata.rb', line 219

def pagination
  .fetch("pagination", nil)
end

#publication_yearObject



321
322
323
# File 'lib/bolognese/metadata.rb', line 321

def publication_year
  date_published.present? ? date_published[0..3].to_i.presence : nil
end


307
308
309
# File 'lib/bolognese/metadata.rb', line 307

def related_identifier_hsh(relation_type)
  Array.wrap(send(relation_type)).map { |r| r.merge("relationType" => relation_type.camelize) }
end

#resource_type_generalObject



143
144
145
# File 'lib/bolognese/metadata.rb', line 143

def resource_type_general
  .fetch("resource_type_general", nil)
end

#titleObject



155
156
157
# File 'lib/bolognese/metadata.rb', line 155

def title
  .fetch("title", nil)
end

#typeObject



123
124
125
# File 'lib/bolognese/metadata.rb', line 123

def type
  .fetch("type", nil)
end

#valid?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/bolognese/metadata.rb', line 107

def valid?
  exists? && errors.nil?
end