Class: AnyStyle::Normalizer::Date
Instance Attribute Summary
#keys, #skip
Instance Method Summary
collapse
#append, #detect_language, #detect_scripts, #doi_extract, #each_value, #initialize, #keys_for, #map_values, #name, #skip?
Instance Method Details
#approximate?(date) ⇒ Boolean
49
50
51
|
# File 'lib/anystyle/normalizer/date.rb', line 49
def approximate?(date)
date =~ /(\b(circa|ca\.|vers|approx))|(^[cv]\.)/i
end
|
69
70
71
72
73
74
75
|
# File 'lib/anystyle/normalizer/date.rb', line 69
def (date)
if date =~ /\b([012]?\d|3[01])\b/
'%02d' % $1.to_i
else
nil
end
end
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/anystyle/normalizer/date.rb', line 77
def (date)
case date
when /\bjan/i
'01'
when /\bf(eb|év)/i
'02'
when /\bmar/i
'03'
when /\ba[pv]r/i
'04'
when /\bma[yi]/i
'05'
when /\bjui?n/i
'06'
when /\bjui?l/i
'07'
when /\ba(ug|oût)/i
'08'
when /\bsep/i
'09'
when /\bo[ck]t/i
'10'
when /\bnov/i
'11'
when /\bd[eé]c/i
'12'
else
nil
end
end
|
53
54
55
56
57
58
59
|
# File 'lib/anystyle/normalizer/date.rb', line 53
def (date)
if approximate?(date)
uncertain?(date) ? '%' : '~'
else
uncertain?(date) ? '?' : nil
end
end
|
61
62
63
64
65
66
67
|
# File 'lib/anystyle/normalizer/date.rb', line 61
def (date)
if date =~ /\D?([012]\d\d\d)\D?/
$1
else
nil
end
end
|
#interval?(date) ⇒ Boolean
37
38
39
|
# File 'lib/anystyle/normalizer/date.rb', line 37
def interval?(date)
date =~ /\/|\s\p{Pd}\s|(\s([12]?\d|30)\p{Pd}([12]?\d|3[01])?)/
end
|
#iso?(date) ⇒ Boolean
33
34
35
|
# File 'lib/anystyle/normalizer/date.rb', line 33
def iso?(date)
date =~ /[012]\d\d\d-\d\d-\d\d/
end
|
#normalize(item, **opts) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/anystyle/normalizer/date.rb', line 6
def normalize(item, **opts)
map_values(item) do |_, value|
case
when unknown?(value)
'XXXX'
when interval?(value)
value
when iso?(value)
value
else
year = (value)
unless year.nil?
month = (value)
day = (value) unless month.nil?
[
[year, month, day].compact.join('-'),
(value)
].compact.join('')
else
value
end
end
end
end
|
#uncertain?(date) ⇒ Boolean
45
46
47
|
# File 'lib/anystyle/normalizer/date.rb', line 45
def uncertain?(date)
date =~ /\?/
end
|
#unknown?(date) ⇒ Boolean
41
42
43
|
# File 'lib/anystyle/normalizer/date.rb', line 41
def unknown?(date)
date =~ /inconnue|unknown|unbekannt|[ns]\. ?d\b|no date/i
end
|