pigeon_band 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -6
- data/lib/pigeon_band.rb +26 -18
- data/lib/pigeon_band/version.rb +2 -1
- data/pigeon_band.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9bb12b73441bd04685095520d4beb619b64b821
|
4
|
+
data.tar.gz: db6173092cf90a4a29deb5ca97dc3bc602744114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 855afe5fddec55de982a639dcef2fede78965998f28a14db6e0e737db3296a4d72fe668a0c64d2335d4760926bf4f5108f049b4f648cb5da32752c259da23bbc
|
7
|
+
data.tar.gz: cd104cd192bc447279a57ff88d7ceb2e1e164b943a15d1d9ed07b6771bb6c9f7e85622359f618a448fac73140f1c1db51cb7bc4b221b3c1a4854c8e327c2789f
|
data/README.md
CHANGED
@@ -35,12 +35,7 @@ above bands a input, a call to PigeonBand#format would return the following hash
|
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
PigeonBand.format("DV-06914-12-479")
|
38
|
-
{
|
39
|
-
band: "DV-06914-12-479"
|
40
|
-
slug: "DV-06914-12-0479"
|
41
|
-
year: 2012
|
42
|
-
code: "DE"
|
43
|
-
}
|
38
|
+
{ band: "DV-06914-12-479" coll: "DV-06914-12-0479" year: 2012 code: "DE" }
|
44
39
|
```
|
45
40
|
## Development
|
46
41
|
|
data/lib/pigeon_band.rb
CHANGED
@@ -2,7 +2,7 @@ require "pigeon_band/version"
|
|
2
2
|
|
3
3
|
module PigeonBand
|
4
4
|
def self.format(band, country = COUNTRY)
|
5
|
-
|
5
|
+
return { error: "missing input for pigeon band" } if band.nil? or band.match(/\A[[:space:]]*\z/)
|
6
6
|
band_msg = "in pigeon band '#{band}'"
|
7
7
|
band.upcase!
|
8
8
|
band.tr!('. /', '---')
|
@@ -11,49 +11,57 @@ module PigeonBand
|
|
11
11
|
case list[0]
|
12
12
|
when 'B'
|
13
13
|
year = get_year(band, list[1], band_msg)
|
14
|
+
return year if year.is_a?(Hash)
|
14
15
|
sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
|
16
|
+
return sequ if sequ.is_a?(Hash)
|
15
17
|
band = sprintf("B-%02d-%07d", year % 100, sequ)
|
16
|
-
|
18
|
+
coll = band
|
17
19
|
code = 'BE'
|
18
20
|
when 'DV'
|
19
21
|
club = get_number(band, list[1], "club", 1, 9999, band_msg)
|
22
|
+
return club if club.is_a?(Hash)
|
20
23
|
year = get_year(band, list[2], band_msg)
|
24
|
+
return year if year.is_a?(Hash)
|
21
25
|
sequ = get_number(band, list[3], "counter", 1, 9999, band_msg)
|
26
|
+
return sequ if sequ.is_a?(Hash)
|
22
27
|
band = sprintf("DV-0%d-%02d-%d", club, year % 100, sequ)
|
23
|
-
|
28
|
+
coll = sprintf("DV-%05d-%02d-%04d", club, year % 100, sequ)
|
24
29
|
code = 'DE'
|
25
30
|
when 'NL'
|
26
31
|
year = get_year(band, list[1], band_msg)
|
32
|
+
return year if year.is_a?(Hash)
|
27
33
|
sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
|
34
|
+
return sequ if sequ.is_a?(Hash)
|
28
35
|
band = sprintf("NL-%02d-%07d", year % 100, sequ)
|
29
|
-
|
36
|
+
coll = band
|
30
37
|
code = 'NL'
|
31
38
|
else
|
32
|
-
|
39
|
+
url = PigeonBand::HOMEPAGE
|
40
|
+
return { error: "unknown country '#{list[0]}'. Please add more countries at #{url}" }
|
33
41
|
end
|
34
|
-
{ band: band,
|
42
|
+
{ band: band, coll: coll, year: year, code: code, error: nil}
|
35
43
|
end
|
36
44
|
|
37
45
|
private
|
38
46
|
|
47
|
+
def self.get_number(band, num, num_type, min_num, max_num, band_msg)
|
48
|
+
return { error: "missing #{num_type} #{band_msg}" } if num.nil? or num.empty?
|
49
|
+
return { error: "invalid #{num_type} '#{num}' #{band_msg}" } unless num.match(/^\d/)
|
50
|
+
num = num.to_i
|
51
|
+
return { error: "#{num_type} '#{num}' too small #{band_msg}" } if num < min_num
|
52
|
+
return { error: "#{num_type} '#{num}' too big #{band_msg}" } if num > max_num
|
53
|
+
return num
|
54
|
+
end
|
55
|
+
|
39
56
|
def self.get_year(band, year, band_msg)
|
40
|
-
|
41
|
-
|
57
|
+
return { error: "missing year #{band_msg}" } if year.nil? or year.empty?
|
58
|
+
return { error: "invalid year '#{year}' #{band_msg}" } unless year.match(/^\d/)
|
42
59
|
year = year.to_i
|
43
|
-
|
60
|
+
return { error: "year '#{year}' out of range #{band_msg}" } if year < 0 or year > 99
|
44
61
|
year += 2000
|
45
62
|
year -= 100 if year > (Time.now.to_date.year + 5)
|
46
63
|
return year
|
47
64
|
end
|
48
|
-
|
49
|
-
def self.get_number(band, num, num_type, min_num, max_num, band_msg)
|
50
|
-
raise "missing #{num_type} #{band_msg}" if num.nil? or num == ""
|
51
|
-
raise "invalid #{num_type} '#{num}' #{band_msg}" unless num.match(/^\d/)
|
52
|
-
num = num.to_i
|
53
|
-
raise "#{num_type} '#{num}' too small #{band_msg}" if num < min_num
|
54
|
-
raise "#{num_type} '#{num}' too big #{band_msg}" if num > max_num
|
55
|
-
return num
|
56
|
-
end
|
57
65
|
end
|
58
66
|
|
59
67
|
# vim: set et ts=2 sw=2 ai:
|
data/lib/pigeon_band/version.rb
CHANGED
data/pigeon_band.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["volker.wiegand@cvw.de"]
|
11
11
|
spec.summary = %q{Pigeon band formatter}
|
12
12
|
spec.description = %q{Format year and collation sequence for pigeon bands of various countries}
|
13
|
-
spec.homepage =
|
13
|
+
spec.homepage = PigeonBand::HOMEPAGE
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pigeon_band
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volker Wiegand
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|