Class: AnyStyle::Normalizer::Volume

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

Constant Summary collapse

VOLNUM_RX =
'(\p{Lu}?\d+|[IVXLCDM]+)'

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/anystyle/normalizer/volume.rb', line 8

def normalize(item, **opts)
  map_values(item, [:volume]) do |_, volume|
    volume = StringUtils.strip_html volume

    unless item.key?(:date)
      unless volume.sub!(/([12]\d{3});|\(([12]\d{3})\)|\/([12]\d{3})/, '').nil?
        append item, :date, $1 || $2 || $3
      end
    end

    case volume
    when /(?:^|\s)#{VOLNUM_RX}\s?\(([^)]+)\)[;:,]?(?:pp?.?)?(\s?\d+\p{Pd}\d+)?/
      volume = $1
      append item, :issue, $2
      append item, :pages, $3.strip unless $3.nil?
      volume
    when /(?:#{VOLNUM_RX}
          (?:\.?\s*J(?:ahrgan)?g\.?)?
          [\p{P}\s]+)?(?:nos?|nr|n°|nº|iss?|fasc|heft|h)\.?\s?(.+)$/ix
      volume = $1
      append item, :issue, $2.sub(/\p{P}$/, '')
      volume
    when /#{VOLNUM_RX}:(\d+(\p{Pd}\d+)?)/
      volume = $1
      append item, (($3.nil? || item.key?(:pages)) ? :issue : :pages), $2
      volume
    when /#{VOLNUM_RX}[\.\/](\S+)/
      volume = $1
      append item, :issue, $2.sub(/\p{P}$/, '')
      volume
    when /(\d+) [Vv]ol/, /J(?:ahrgan)?g\.? (\d+)/
      $1
    else
      volume
        .sub(/<\/?(italic|i|strong|b|span|div)>/, '')
        .sub(/^[\p{P}\s]+/, '')
        .sub(/^[Vv]ol(ume)?[\p{P}\s]+/, '')
        .sub(/[\p{P}\p{Z}\p{C}]+$/, '')
    end
  end
end