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, #each_value, #keys_for, #map_values, #name, #skip?

Constructor Details

#initializeLocale

Returns a new instance of Locale.



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

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

Instance Method Details

#normalize(item, **opts) ⇒ Object



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

def normalize(item, **opts)
  return item if @ld.nil? || item.key?(:language)

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

  return item if sample.empty?

  item[:language] = @ld.detect(sample)
  item
end