Class: AnyStyle::Normalizer::Locator

Inherits:
AnyStyle::Normalizer show all
Defined in:
lib/anystyle/normalizer/locator.rb

Instance Attribute Summary

Attributes inherited from AnyStyle::Normalizer

#keys, #skip

Instance Method Summary collapse

Methods inherited from AnyStyle::Normalizer

#append, #detect_language, #detect_scripts, #doi_extract, #each_value, #initialize, #keys_for, #map_values, #name, #skip?

Constructor Details

This class inherits a constructor from AnyStyle::Normalizer

Instance Method Details

#normalize(item, **opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/anystyle/normalizer/locator.rb', line 8

def normalize(item, **opts)
  map_values(item) do |key, value|
    case key
    when :isbn
      value[/[\d-]+/]
    when :url
      doi = doi_extract(value) if value =~ /doi\.org\//i
      append item, :doi, doi unless doi.nil?
      urls = URI.extract(value, %w(http https ftp ftps))
      if urls.empty?
        value
      else
        urls
      end
    when :doi
      doi_extract(value) || value
    else
      value
    end
  end
end