Class: Commonmeta::CLI

Inherits:
Thor
  • Object
show all
Includes:
DoiUtils, Readers::JsonFeedReader, Utils
Defined in:
lib/commonmeta/cli.rb

Constant Summary

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Readers::JsonFeedReader

#get_doi_prefix_by_blog_slug, #get_doi_prefix_by_json_feed_item_id, #get_files, #get_funding_references, #get_json_feed_blog_slug, #get_json_feed_by_blog, #get_json_feed_item, #get_json_feed_unregistered, #get_json_feed_updated, #get_references, #get_related_identifiers, #read_json_feed_item

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_unregistered_url, #json_feed_updated_url, #jsonlint, #map_hash_keys, #name_to_fos, #name_to_spdx, #normalize_cc_url, #normalize_id, #normalize_isni, #normalize_issn, #normalize_licenses, #normalize_name_identifier, #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_isni, #validate_orcid, #validate_orcid_scheme, #validate_ror, #validate_url

Methods included from DoiUtils

#crossref_api_url, #datacite_api_url, #doi_as_url, #doi_from_url, #doi_resolver, #get_crossref_member, #get_doi_ra, #is_rogue_scholar_doi?, #normalize_doi, #validate_doi, #validate_funder_doi, #validate_prefix

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/commonmeta/cli.rb', line 14

def self.exit_on_failure?
  true
end

Instance Method Details

#__print_versionObject



23
24
25
# File 'lib/commonmeta/cli.rb', line 23

def __print_version
  puts Commonmeta::VERSION
end

#convert(input) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/commonmeta/cli.rb', line 39

def convert(input)
   = Metadata.new(input: input,
                          from: options[:from],
                          regenerate: options[:regenerate],
                          style: options[:style],
                          locale: options[:locale],
                          show_errors: options[:show_errors],
                          doi: options[:doi],
                          depositor: options[:depositor],
                          email: options[:email],
                          registrant: options[:registrant])
  to = options[:to] || "schema_org"

  if options[:show_errors] && !.valid?
    warn .errors
  else
    puts .send(to)
  end
end

#decode(doi) ⇒ Object



90
91
92
# File 'lib/commonmeta/cli.rb', line 90

def decode(doi)
  puts decode_doi(doi)
end

#decode_id(id) ⇒ Object



96
97
98
# File 'lib/commonmeta/cli.rb', line 96

def decode_id(id)
  puts decode_container_id(id)
end

#encode(prefix) ⇒ Object



61
62
63
64
# File 'lib/commonmeta/cli.rb', line 61

def encode(prefix)
  return nil unless validate_prefix(prefix).present?
  puts encode_doi(prefix)
end

#encode_by_blog(blog_slug) ⇒ Object



74
75
76
77
78
# File 'lib/commonmeta/cli.rb', line 74

def encode_by_blog(blog_slug)
  prefix = get_doi_prefix_by_blog_slug(blog_slug)
  return nil unless prefix.present?
  puts encode_doi(prefix)
end

#encode_by_id(id) ⇒ Object



82
83
84
85
86
# File 'lib/commonmeta/cli.rb', line 82

def encode_by_id(id)
  prefix = get_doi_prefix_by_json_feed_item_id(id)
  return nil unless prefix.present?
  puts encode_doi(prefix)
end

#encode_idObject



68
69
70
# File 'lib/commonmeta/cli.rb', line 68

def encode_id
  puts encode_container_id
end

#generate_ghost_api_tokenObject



132
133
134
135
# File 'lib/commonmeta/cli.rb', line 132

def generate_ghost_api_token
  # generate short lived jwt for ghost admin api
  puts generate_ghost_token
end

#json_feed_blog_slug(slug) ⇒ Object



120
121
122
# File 'lib/commonmeta/cli.rb', line 120

def json_feed_blog_slug(slug)
  puts get_json_feed_blog_slug(slug)
end

#json_feed_by_blog(id) ⇒ Object



114
115
116
# File 'lib/commonmeta/cli.rb', line 114

def json_feed_by_blog(id)
  puts get_json_feed_by_blog(id)
end

#json_feed_unregisteredObject



102
103
104
# File 'lib/commonmeta/cli.rb', line 102

def json_feed_unregistered
  puts get_json_feed_unregistered
end

#json_feed_updatedObject



108
109
110
# File 'lib/commonmeta/cli.rb', line 108

def json_feed_updated
  puts get_json_feed_updated
end

#update_ghost_post(id) ⇒ Object



126
127
128
# File 'lib/commonmeta/cli.rb', line 126

def update_ghost_post(id)
  puts update_ghost_post_via_api(id)
end