Sha256: f4427816c767f459c1ddd08c0dc3c47e8798071626d26231b0357ad30594c53e
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
require_relative 'metadata_utils' module Bolognese class Metadata include Bolognese::MetadataUtils def initialize(input: nil, from: nil, **options) id = normalize_id(input, options) 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: options[:sandbox]) : {} string = hsh.fetch("string", 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 hsh = { "b_url" => options[:b_url], "state" => options[:state], "date_registered" => options[:date_registered], "date_updated" => options[:date_updated], "provider_id" => options[:provider_id], "client_id" => options[:client_id] } 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 = options[:style] @locale = options[:locale] @regenerate = options[:regenerate] @sandbox = options[:sandbox] # options that come from the datacite database @b_doi = normalize_doi(options[:doi] || input, options) @b_url = hsh.to_h["b_url"].presence || options[: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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bolognese-0.9.96 | lib/bolognese/metadata.rb |