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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c068f38af42b53131bb136a6ad108e06de31f2d2
4
- data.tar.gz: cb14f929059911297cd641889c7ee823fea2515a
3
+ metadata.gz: b4f596ce451ea151bfec0ba842528aea903ccadd
4
+ data.tar.gz: ce1bba537837b579f5cef50119921775cb7565a9
5
5
  SHA512:
6
- metadata.gz: 9e6d54d61de19af266e2a451ca497ff4d9dc173e741afa96165beaf29993f4bc71b12659b60a9f58298237952550f9fc32048c0d1eaa935bf746be97e5a7a84c
7
- data.tar.gz: d40911654fd7f86e5ba15d390e0bfac2d44820be38152c8dd6050ddff0bf45ae402bc5f5d8caa0c78b8264e34ab1c7b4463c38749e6974bd644e0a6c1e48eb39
6
+ metadata.gz: 6fd01f51b0ced92e93d55681a87189be06fff73fdf7be902284f603bd25eaa448cbcc6c0cb9949f6b27c9bf54918534ba4f779af080edc4fe0dd8f57c2f19ca8
7
+ data.tar.gz: d8ebbc5e12d7cc5df095f98b20a103931d8562c01d262f38ed174aa46b2b1a0b3e38637ce804c31659ad2e158a9d1f8a0f7d588a8c23007d0967f8529ac532d1
data/Makefile CHANGED
@@ -19,8 +19,13 @@ install: build
19
19
  rake install
20
20
  rm -rf pkg
21
21
 
22
+ update: build
23
+ gem uninstall pigeon_band --all
24
+ rake install
25
+
22
26
  build:
23
27
  git add lib
24
28
  git add test
25
29
  rake test
30
+ vim README.md
26
31
 
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. Thus, given the
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" error: nil }
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.
@@ -1,5 +1,5 @@
1
1
  module PigeonBand
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  COUNTRY = "DV"
4
4
  HOMEPAGE = "https://github.com/volkerwiegand/pigeon_band"
5
5
  end
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: "missing input for pigeon band" } if band.nil? or band.match(/\A[[:space:]]*\z/)
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], band_msg)
12
+ year = get_year(band, list[1])
14
13
  return year if year.is_a?(Hash)
15
- sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
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, band_msg)
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], band_msg)
22
+ year = get_year(band, list[2])
24
23
  return year if year.is_a?(Hash)
25
- sequ = get_number(band, list[3], "counter", 1, 9999, band_msg)
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], band_msg)
30
+ year = get_year(band, list[1])
32
31
  return year if year.is_a?(Hash)
33
- sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
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
- url = PigeonBand::HOMEPAGE
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, 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/)
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} '#{num}' too small #{band_msg}" } if num < min_num
52
- return { error: "#{num_type} '#{num}' too big #{band_msg}" } if num > max_num
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, band_msg)
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/)
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: "year '#{year}' out of range #{band_msg}" } if year < 0 or year > 99
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigeon_band
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volker Wiegand