4
5
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
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/pigeon_band.rb', line 4
def self.format(band, country = COUNTRY)
return { error: "input_missing" } if band.nil? or band.match(/\A[[:space:]]*\z/)
band.upcase!
band.tr!('. /', '---')
band = country + '-' + band unless band.match(/^[A-Z]/)
list = band.split('-')
case list[0]
when 'B'
year = get_year(band, list[1])
return year if year.is_a?(Hash)
sequ = get_number(band, list[2], "sequ", 1000001, 9999999)
return sequ if sequ.is_a?(Hash)
band = sprintf("B-%02d-%07d", year % 100, sequ)
coll = band
code = 'BE'
when 'DV'
club = get_number(band, list[1], "club", 1, 9999)
return club if club.is_a?(Hash)
year = get_year(band, list[2])
return year if year.is_a?(Hash)
sequ = get_number(band, list[3], "sequ", 1, 9999)
return sequ if sequ.is_a?(Hash)
band = sprintf("DV-0%d-%02d-%d", club, year % 100, sequ)
coll = sprintf("DV-%05d-%02d-%04d", club, year % 100, sequ)
code = 'DE'
when 'NL'
year = get_year(band, list[1])
return year if year.is_a?(Hash)
sequ = get_number(band, list[2], "sequ", 1000001, 9999999)
return sequ if sequ.is_a?(Hash)
band = sprintf("NL-%02d-%07d", year % 100, sequ)
coll = band
code = 'NL'
else
return { error: "country_unknown" }
end
{ band: band, coll: coll, year: year, code: code, error: nil }
end
|