Module: PigeonBand

Defined in:
lib/pigeon_band.rb,
lib/pigeon_band/version.rb

Constant Summary collapse

VERSION =
"1.0.1"
COUNTRY =
"DV"
HOMEPAGE =
"https://github.com/volkerwiegand/pigeon_band"

Class Method Summary collapse

Class Method Details

.format(band, country = COUNTRY) ⇒ Object



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
42
43
# File 'lib/pigeon_band.rb', line 4

def self.format(band, country = COUNTRY)
  return { error: "missing input for pigeon band" } if band.nil? or band.match(/\A[[:space:]]*\z/)
  band_msg = "in pigeon band '#{band}'"
  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], band_msg)
      return year if year.is_a?(Hash)
      sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
      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, band_msg)
      return club if club.is_a?(Hash)
      year = get_year(band, list[2], band_msg)
      return year if year.is_a?(Hash)
      sequ = get_number(band, list[3], "counter", 1, 9999, band_msg)
      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], band_msg)
      return year if year.is_a?(Hash)
      sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
      return sequ if sequ.is_a?(Hash)
      band = sprintf("NL-%02d-%07d", year % 100, sequ)
      coll = band
      code = 'NL'
    else
      url = PigeonBand::HOMEPAGE
      return { error: "unknown country '#{list[0]}'. Please add more countries at #{url}" }
  end
  { band: band, coll: coll, year: year, code: code, error: nil}
end