Skip to content

Commit

Permalink
add commonmeta reader
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Jan 13, 2024
1 parent 811e8ad commit 1e18026
Show file tree
Hide file tree
Showing 10 changed files with 503 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
commonmeta-ruby (3.8.3)
commonmeta-ruby (3.9.0)
activesupport (>= 4.2.5, < 8.0)
addressable (~> 2.8.1, < 2.8.2)
base32-url (>= 0.7.0, < 1)
Expand Down Expand Up @@ -132,17 +132,18 @@ GEM
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
matrix (0.4.2)
minitest (5.20.0)
minitest (5.21.1)
multi_json (1.15.0)
mutex_m (0.2.0)
namae (1.1.1)
namae (1.2.0)
racc (~> 1.7)
nokogiri (1.16.0-arm64-darwin)
racc (~> 1.4)
oj (3.16.3)
bigdecimal (>= 3.0)
optimist (3.1.0)
parallel (1.24.0)
parser (3.3.0.2)
parser (3.3.0.3)
ast (~> 2.4.1)
racc
postrank-uri (1.1)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 - 2021 DataCite, 2021 Front Matter
Copyright (c) 2017 - 2021 DataCite, 2021 - 2024 Front Matter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions lib/commonmeta/metadata_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative 'readers/cff_reader'
require_relative 'readers/csl_reader'
require_relative 'readers/codemeta_reader'
require_relative 'readers/commonmeta_reader'
require_relative 'readers/crossref_reader'
require_relative 'readers/crossref_xml_reader'
require_relative 'readers/datacite_reader'
Expand Down Expand Up @@ -44,6 +45,7 @@ module MetadataUtils
include Commonmeta::Readers::BibtexReader
include Commonmeta::Readers::CffReader
include Commonmeta::Readers::CodemetaReader
include Commonmeta::Readers::CommonmetaReader
include Commonmeta::Readers::CrossrefReader
include Commonmeta::Readers::CrossrefXmlReader
include Commonmeta::Readers::CslReader
Expand Down
20 changes: 20 additions & 0 deletions lib/commonmeta/readers/commonmeta_reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Commonmeta
module Readers
module CommonmetaReader
def read_commonmeta(string: nil, **options)
if string.present?
errors = jsonlint(string)
return { "errors" => errors } if errors.present?
end

read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url,
:sandbox, :validate, :ra))
meta = string.present? ? JSON.parse(string) : {}
meta["schema_version"] = "https://commonmeta.org/commonmeta_v0.10.5.json"
meta.compact.merge(read_options)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/commonmeta/schema_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module Commonmeta
module SchemaUtils
COMMONMETA = File.read(File.expand_path("../../resources/commonmeta_v0.10.4.json",
COMMONMETA = File.read(File.expand_path("../../resources/commonmeta_v0.10.5.json",
__dir__))

def json_schema_errors
Expand Down
4 changes: 3 additions & 1 deletion lib/commonmeta/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ def find_from_format_by_ext(string, options = {})
def find_from_format_by_string(string)
begin # try to parse as JSON
hsh = MultiJson.load(string).to_h
if hsh.dig("@context") && URI.parse(hsh.dig("@context")).host == "schema.org"
if hsh.dig("schema_version").to_s.start_with?("https://commonmeta.org")
return "commonmeta"
elsif hsh.dig("@context") && URI.parse(hsh.dig("@context")).host == "schema.org"
return "schema_org"
elsif hsh.dig("schemaVersion").to_s.start_with?("http://datacite.org/schema/kernel")
return "datacite"
Expand Down
2 changes: 1 addition & 1 deletion lib/commonmeta/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Commonmeta
VERSION = '3.8.3'
VERSION = '3.9.0'
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://commonmeta.org/commonmeta_v0.10.4.json",
"title": "Commonmeta v0.10.4",
"$id": "https://commonmeta.org/commonmeta_v0.10.5.json",
"title": "Commonmeta v0.10.5",
"description": "JSON representation of the Commonmeta schema.",
"additionalProperties": false,
"definitions": {
Expand Down Expand Up @@ -508,6 +508,7 @@
"description": "The schema version of the resource.",
"type": "string",
"enum": [
"https://commonmeta.org/commonmeta_v0.10.5.json",
"http://datacite.org/schema/kernel-3",
"http://datacite.org/schema/kernel-4"
]
Expand Down
Loading

0 comments on commit 1e18026

Please sign in to comment.