pigeon_band 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +5 -0
- data/README.md +39 -3
- data/lib/pigeon_band/version.rb +1 -1
- data/lib/pigeon_band.rb +19 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f596ce451ea151bfec0ba842528aea903ccadd
|
4
|
+
data.tar.gz: ce1bba537837b579f5cef50119921775cb7565a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fd01f51b0ced92e93d55681a87189be06fff73fdf7be902284f603bd25eaa448cbcc6c0cb9949f6b27c9bf54918534ba4f779af080edc4fe0dd8f57c2f19ca8
|
7
|
+
data.tar.gz: d8ebbc5e12d7cc5df095f98b20a103931d8562c01d262f38ed174aa46b2b1a0b3e38637ce804c31659ad2e158a9d1f8a0f7d588a8c23007d0967f8529ac532d1
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -30,8 +30,7 @@ Or install it yourself as:
|
|
30
30
|
## Usage
|
31
31
|
|
32
32
|
After loading the pigeon_band gem, there is a new object PigeonBand with one method #format.
|
33
|
-
Given a band as a string, it returns a hash consisting of five fields.
|
34
|
-
above bands a input, a call to PigeonBand#format would return the following hashes:
|
33
|
+
Given a band as a string, it returns a hash consisting of five fields.
|
35
34
|
|
36
35
|
* band
|
37
36
|
* The normalized band as it should be displayed
|
@@ -44,10 +43,47 @@ above bands a input, a call to PigeonBand#format would return the following hash
|
|
44
43
|
* error
|
45
44
|
* The error message if the band is invalid, otherwise nil
|
46
45
|
|
46
|
+
Given the above bands a input, a call to PigeonBand#format would return the following hashes:
|
47
|
+
|
47
48
|
```ruby
|
48
49
|
PigeonBand.format("DV-06914-12-479")
|
49
|
-
{ band: "DV-06914-12-479" coll: "DV-06914-12-0479" year: 2012 code: "DE"
|
50
|
+
{ band: "DV-06914-12-479", coll: "DV-06914-12-0479", year: 2012, code: "DE", error: nil }
|
51
|
+
|
52
|
+
PigeonBand.format("DV-099-09-850")
|
53
|
+
{ band: "DV-099-09-850", coll: "DV-00099-09-0850", year: 2009, code: "DE", error: nil }
|
50
54
|
```
|
55
|
+
|
56
|
+
## Error messages
|
57
|
+
|
58
|
+
The following error messages are sent when the corresponding error is detected:
|
59
|
+
|
60
|
+
* input_missing
|
61
|
+
* The input is blank or consists entirely of white space.
|
62
|
+
|
63
|
+
* country_unknown
|
64
|
+
* The given country was not recognized.
|
65
|
+
* You can help improving this gem by contributing it :-)
|
66
|
+
* See below for details.
|
67
|
+
|
68
|
+
* year_range
|
69
|
+
* The given year is outside the valid range of 00 to 99
|
70
|
+
|
71
|
+
* club_below
|
72
|
+
* The given club (for countries with club numbers) is too low
|
73
|
+
|
74
|
+
* club_above
|
75
|
+
* The given club (for countries with club numbers) is too high
|
76
|
+
|
77
|
+
* sequ_below
|
78
|
+
* The given running number is too low
|
79
|
+
|
80
|
+
* sequ_above
|
81
|
+
* The given running number is too high
|
82
|
+
|
83
|
+
## Complete Rails example
|
84
|
+
|
85
|
+
TODO: show model, controller, view, route and locale data
|
86
|
+
|
51
87
|
## Development
|
52
88
|
|
53
89
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/pigeon_band/version.rb
CHANGED
data/lib/pigeon_band.rb
CHANGED
@@ -2,62 +2,60 @@ require "pigeon_band/version"
|
|
2
2
|
|
3
3
|
module PigeonBand
|
4
4
|
def self.format(band, country = COUNTRY)
|
5
|
-
return { error: "
|
6
|
-
band_msg = "in pigeon band '#{band}'"
|
5
|
+
return { error: "input_missing" } if band.nil? or band.match(/\A[[:space:]]*\z/)
|
7
6
|
band.upcase!
|
8
7
|
band.tr!('. /', '---')
|
9
8
|
band = country + '-' + band unless band.match(/^[A-Z]/)
|
10
9
|
list = band.split('-')
|
11
10
|
case list[0]
|
12
11
|
when 'B'
|
13
|
-
year = get_year(band, list[1]
|
12
|
+
year = get_year(band, list[1])
|
14
13
|
return year if year.is_a?(Hash)
|
15
|
-
sequ = get_number(band, list[2], "
|
14
|
+
sequ = get_number(band, list[2], "sequ", 1000001, 9999999)
|
16
15
|
return sequ if sequ.is_a?(Hash)
|
17
16
|
band = sprintf("B-%02d-%07d", year % 100, sequ)
|
18
17
|
coll = band
|
19
18
|
code = 'BE'
|
20
19
|
when 'DV'
|
21
|
-
club = get_number(band, list[1], "club", 1, 9999
|
20
|
+
club = get_number(band, list[1], "club", 1, 9999)
|
22
21
|
return club if club.is_a?(Hash)
|
23
|
-
year = get_year(band, list[2]
|
22
|
+
year = get_year(band, list[2])
|
24
23
|
return year if year.is_a?(Hash)
|
25
|
-
sequ = get_number(band, list[3], "
|
24
|
+
sequ = get_number(band, list[3], "sequ", 1, 9999)
|
26
25
|
return sequ if sequ.is_a?(Hash)
|
27
26
|
band = sprintf("DV-0%d-%02d-%d", club, year % 100, sequ)
|
28
27
|
coll = sprintf("DV-%05d-%02d-%04d", club, year % 100, sequ)
|
29
28
|
code = 'DE'
|
30
29
|
when 'NL'
|
31
|
-
year = get_year(band, list[1]
|
30
|
+
year = get_year(band, list[1])
|
32
31
|
return year if year.is_a?(Hash)
|
33
|
-
sequ = get_number(band, list[2], "
|
32
|
+
sequ = get_number(band, list[2], "sequ", 1000001, 9999999)
|
34
33
|
return sequ if sequ.is_a?(Hash)
|
35
34
|
band = sprintf("NL-%02d-%07d", year % 100, sequ)
|
36
35
|
coll = band
|
37
36
|
code = 'NL'
|
38
37
|
else
|
39
|
-
|
40
|
-
return { error: "unknown country '#{list[0]}'. Please add more countries at #{url}" }
|
38
|
+
return { error: "country_unknown" }
|
41
39
|
end
|
42
|
-
{ band: band, coll: coll, year: year, code: code, error: nil}
|
40
|
+
{ band: band, coll: coll, year: year, code: code, error: nil }
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
46
44
|
|
47
|
-
def self.get_number(band, num, num_type, min_num, max_num
|
48
|
-
return { error: "
|
49
|
-
return { error: "
|
45
|
+
def self.get_number(band, num, num_type, min_num, max_num)
|
46
|
+
return { error: "#{num_type}_missing" } if num.nil? or num.empty?
|
47
|
+
return { error: "#{num_type}_invalid" } unless num.match(/^\d/)
|
50
48
|
num = num.to_i
|
51
|
-
return { error: "#{num_type}
|
52
|
-
return { error: "#{num_type}
|
49
|
+
return { error: "#{num_type}_below" } if num < min_num
|
50
|
+
return { error: "#{num_type}_above" } if num > max_num
|
53
51
|
return num
|
54
52
|
end
|
55
53
|
|
56
|
-
def self.get_year(band, year
|
57
|
-
return { error: "
|
58
|
-
return { error: "
|
54
|
+
def self.get_year(band, year)
|
55
|
+
return { error: "year_missing" } if year.nil? or year.empty?
|
56
|
+
return { error: "year_invalid" } unless year.match(/^\d/)
|
59
57
|
year = year.to_i
|
60
|
-
return { error: "
|
58
|
+
return { error: "year_range" } if year < 0 or year > 99
|
61
59
|
year += 2000
|
62
60
|
year -= 100 if year > (Time.now.to_date.year + 5)
|
63
61
|
return year
|