Skip to content

Commit

Permalink
Add DOI normalizer
Browse files Browse the repository at this point in the history
Closes #113
  • Loading branch information
inukshuk committed Sep 14, 2018
1 parent fcf355f commit 964f896
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/anystyle/normalizer/locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module AnyStyle

class Normalizer
class Locator < Normalizer
@keys = [:isbn, :url]
@keys = [:isbn, :url, :doi]

def normalize(item, **opts)
map_values(item) do |key, value|
Expand All @@ -12,6 +12,8 @@ def normalize(item, **opts)
value[/[\d-]+/]
when :url
URI.extract(value)
when :doi
value[/10\.(\d{4,9}\/[-._;()\/:A-Z0-9]+|1002\/\S+)/i] || value
else
value
end
Expand Down
14 changes: 14 additions & 0 deletions spec/anystyle/normalizer/locator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module AnyStyle
describe "Locator Normalizer" do
let(:n) { Normalizer::Locator.new }

it "extracts valid DOIs" do
({
'doi:10.1002/mpr.33.' => { doi: ['10.1002/mpr.33.'] },
'https://doi.org/10.1000/182' => { doi: ['10.1000/182'] }
}).each do |(a, b)|
expect(n.normalize(doi: [a])).to include(b)
end
end
end
end

0 comments on commit 964f896

Please sign in to comment.