Skip to content

Commit

Permalink
simplify input for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 14, 2020
1 parent 1c64196 commit 40f2681
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/bolognese/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Metadata
:format, :funding_references, :state, :geo_locations,
:types, :content_url, :related_identifiers, :style, :locale, :date_registered

def initialize(input: nil, **options)
def initialize(options={})
options.symbolize_keys!
id = normalize_id(input, options)
id = normalize_id(options[:input], options)
ra = nil

if id.present?
Expand All @@ -38,9 +38,9 @@ def initialize(input: nil, **options)
hsh = @from.present? ? send("get_" + @from, id: id, sandbox: options[:sandbox]) : {}
string = hsh.fetch("string", nil)

elsif input.present? && File.exist?(input)
filename = File.basename(input)
ext = File.extname(input)
elsif options[:input].present? && File.exist?(options[:input])
filename = File.basename(options[:input])
ext = File.extname(options[:input])
if %w(.bib .ris .xml .json).include?(ext)
hsh = {
"url" => options[:url],
Expand All @@ -50,7 +50,7 @@ def initialize(input: nil, **options)
"provider_id" => options[:provider_id],
"client_id" => options[:client_id],
"content_url" => options[:content_url] }
string = IO.read(input)
string = IO.read(options[:input])
@from = options[:from] || find_from_format(string: string, filename: filename, ext: ext)
else
$stderr.puts "File type #{ext} not supported"
Expand All @@ -70,7 +70,7 @@ def initialize(input: nil, **options)
"titles" => options[:titles],
"publisher" => options[:publisher],
"publication_year" => options[:publication_year] }
string = input
string = options[:input]
@from = options[:from] || find_from_format(string: string)
end

Expand Down

0 comments on commit 40f2681

Please sign in to comment.