Class: AnyStyle::Normalizer::Location

Inherits:
AnyStyle::Normalizer show all
Defined in:
lib/anystyle/normalizer/location.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



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/anystyle/normalizer/location.rb', line 6

def normalize(item, **opts)
  map_values(item) do |_, value|
    location = strip value

    if !item.key?(:publisher) && location.include?(':')
      location, publisher = location.split(/\s*:\s*/)
      append item, :publisher, publisher
    end

    location
  end
end

#strip(string) ⇒ Object



19
20
21
# File 'lib/anystyle/normalizer/location.rb', line 19

def strip(string)
  string.gsub(/^\p{^Alnum}+|\p{^Alnum}+$/, '')
end