Class: AnyStyle::Normalizer::Locale

Inherits:
AnyStyle::Normalizer show all
Defined in:
lib/anystyle/normalizer/locale.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, #keys_for, #map_values, #name, #skip?

Constructor Details

#initializeLocale

Returns a new instance of Locale.


7
8
9
# File 'lib/anystyle/normalizer/locale.rb', line 7

def initialize
  @ld = LanguageDetector.new if defined?(LanguageDetector)
end

Instance Method Details

#normalize(item, **opts) ⇒ Object


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

def normalize(item, **opts)
  sample = item.values_at(
    :title,
    :'container-title',
    :'collection-title',
    :location,
    :journal,
    :publisher,
    :note
  ).flatten.compact.join(' ')

  return item if sample.empty?

  language = detect_language(sample)
  scripts = detect_scripts(sample)

  item[:language] ||= language unless language.nil?
  item[:scripts] ||= scripts unless scripts.nil?
  item
end