pigeon_band 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89627bdafb67b4c29ff45d574a94a89035841c07
4
+ data.tar.gz: 9a2a36e86ea842aaff7908415f9dcbe3fd31679a
5
+ SHA512:
6
+ metadata.gz: 287cb8976481aa8447c2ebaa9d36556bf4af979f56605f275b9dbe8be51eee237a1d9c4b388002e71fe300dc14766c5306f986d7a14cd2fa22cf6ab099b1443c
7
+ data.tar.gz: cffffe5db7db81b60baa52f800e47eea305dca968f13cfb73cc704c1d16e02b1f3ef86f0751b90420b0601f5aa7c794428b951167da2310e7a1e1fe48bd47955
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pigeon_band.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Volker Wiegand
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,25 @@
1
+ # vim: set ts=8 tw=0 noet :
2
+ #
3
+ # Makefile for building the Gem
4
+ #
5
+
6
+ all: build
7
+ git status
8
+
9
+ rel: build
10
+ vim lib/pigeon_band/version.rb
11
+ git commit -a
12
+ gem uninstall pigeon_band --all
13
+ rake release
14
+
15
+
16
+ install: build
17
+ git commit -a
18
+ gem uninstall pigeon_band --all
19
+ rake install
20
+ rm -rf pkg
21
+
22
+ build:
23
+ git add lib
24
+ git add test
25
+
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # PigeonBand
2
+
3
+ This Ruby gem helps to format and validate racing pigeon bands (a.k.a. rings) from various countries.
4
+
5
+ Different countries use different schemes for band numbers. In Germany (my home country) the format
6
+ is e.g. DV-06914-12-479. It starts with the country code DV (short for "Deutscher Verein").
7
+ Then comes the club number with a leading zero, minimum 01 and maximum 09999.
8
+ Next is the year (last two digits) when the band was issued. Finally there is a running number of
9
+ at most four digits, starting from 1.
10
+
11
+ In Belgium or the Netherlands, pigeons are given a 7-digit running number besides year and country
12
+ designation. Thus, a valid band would be B-08-2148152.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'pigeon_band'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install pigeon_band
29
+
30
+ ## Usage
31
+
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 four fields. Thus, giben the
34
+ above bands a input, a call to PigeonBand#format would return the following hashes:
35
+
36
+ ```ruby
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
+ }
44
+ ```
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/volkerwiegand/pigeon_band.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pigeon_band"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ module PigeonBand
2
+ VERSION = "0.1.0"
3
+ COUNTRY = "DV"
4
+ end
@@ -0,0 +1,59 @@
1
+ require "pigeon_band/version"
2
+
3
+ module PigeonBand
4
+ def self.format(band, country = COUNTRY)
5
+ raise "missing input for pigeon band" if band.nil? or band == ""
6
+ band_msg = "in pigeon band '#{band}'"
7
+ band.upcase!
8
+ band.tr!('. /', '---')
9
+ band = country + '-' + band unless band.match(/^[A-Z]/)
10
+ list = band.split('-')
11
+ case list[0]
12
+ when 'B'
13
+ year = get_year(band, list[1], band_msg)
14
+ sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
15
+ band = sprintf("B-%02d-%07d", year % 100, sequ)
16
+ slug = band
17
+ code = 'BE'
18
+ when 'DV'
19
+ club = get_number(band, list[1], "club", 1, 9999, band_msg)
20
+ year = get_year(band, list[2], band_msg)
21
+ sequ = get_number(band, list[3], "counter", 1, 9999, band_msg)
22
+ band = sprintf("DV-0%d-%02d-%d", club, year % 100, sequ)
23
+ slug = sprintf("DV-%05d-%02d-%04d", club, year % 100, sequ)
24
+ code = 'DE'
25
+ when 'NL'
26
+ year = get_year(band, list[1], band_msg)
27
+ sequ = get_number(band, list[2], "counter", 1, 9999999, band_msg)
28
+ band = sprintf("NL-%02d-%07d", year % 100, sequ)
29
+ slug = band
30
+ code = 'NL'
31
+ else
32
+ raise "Please add more formats at https://github.com/volkerwiegand/pigeon_band"
33
+ end
34
+ { band: band, slug: slug, year: year, code: code }
35
+ end
36
+
37
+ private
38
+
39
+ def self.get_year(band, year, band_msg)
40
+ raise "missing year #{band_msg}" if year.nil? or year == ""
41
+ raise "invalid year '#{year}' #{band_msg}" unless year.match(/^\d/)
42
+ year = year.to_i
43
+ raise "year '#{year}' out of range #{band_msg}" if year < 0 or year > 99
44
+ year += 2000
45
+ year -= 100 if year > (Time.now.to_date.year + 5)
46
+ return year
47
+ 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
+ end
58
+
59
+ # vim: set et ts=2 sw=2 ai:
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pigeon_band/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pigeon_band"
8
+ spec.version = PigeonBand::VERSION
9
+ spec.authors = ["Volker Wiegand"]
10
+ spec.email = ["volker.wiegand@cvw.de"]
11
+ spec.summary = %q{Pigeon band formatter}
12
+ spec.description = %q{Format year and collation sequence for pigeon bands of various countries}
13
+ spec.homepage = "https://github.com/volkerwiegand/pigeon_band"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+ spec.add_dependency 'activerecord', '~> 4.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest"
27
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pigeon_band
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Volker Wiegand
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Format year and collation sequence for pigeon bands of various countries
70
+ email:
71
+ - volker.wiegand@cvw.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - Makefile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/pigeon_band.rb
86
+ - lib/pigeon_band/version.rb
87
+ - pigeon_band.gemspec
88
+ homepage: https://github.com/volkerwiegand/pigeon_band
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.9.3
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Pigeon band formatter
112
+ test_files: []