eu_countries 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/Readme.md +48 -0
- data/eu_countries.gemspec +25 -0
- data/lib/eu_countries/eu_country.rb +22 -0
- data/lib/eu_countries/version.rb +3 -0
- data/lib/eu_countries.rb +2 -0
- data/spec/lib/eu_countries_spec.rb +51 -0
- data/spec/spec_helper.rb +3 -0
- metadata +109 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# EU Countries
|
2
|
+
|
3
|
+
The [countries](http://rubygems.org/gems/countries) gem doesn't take into account whether countries are in the EU or not. So here's an extension to said gem that lists that information.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
In your Gemfile:
|
8
|
+
|
9
|
+
gem "eu_countries"
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Get an array of EU country codes (ISO3611 alpha2 codes):
|
14
|
+
|
15
|
+
ISO3611::EUCountry.codes
|
16
|
+
|
17
|
+
Get an array of `ISO3611::EUCountry` instances for all countries in the EU:
|
18
|
+
|
19
|
+
ISO3611::EUCountry.all
|
20
|
+
|
21
|
+
## Disclaimer
|
22
|
+
|
23
|
+
This list is accurate to the best of my knowledge, but it's your own responsibility to double-check it before using it in anything. I generated the list from <http://www.hmrc.gov.uk/vat/managing/international/esl/country-codes.htm>.
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
MIT License
|
28
|
+
|
29
|
+
Copyright (c) 2011 Brightbox Systems Ltd <hello@brightbox.co.uk>
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "eu_countries/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "eu_countries"
|
7
|
+
s.version = EuCountries::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Caius Durling"]
|
10
|
+
s.email = ["caius@brightbox.co.uk"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{List all countries in the EU}
|
13
|
+
s.description = %q{List all countries in the EU}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "countries"
|
21
|
+
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ISO3166
|
2
|
+
class EUCountry < Country
|
3
|
+
|
4
|
+
# Returns an array of the alpha2 codes for all EU countries
|
5
|
+
def self.codes
|
6
|
+
%w(AT BE BG CY CZ DK EE FI FR DE GB GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns an array of EUCountry instances. By default them all, but you can filter using :except param.
|
10
|
+
def self.all opts={}
|
11
|
+
opts ||= {}
|
12
|
+
da_codes = codes.dup
|
13
|
+
|
14
|
+
if (( exclude = opts.delete(:except) ))
|
15
|
+
da_codes -= Array(exclude)
|
16
|
+
end
|
17
|
+
|
18
|
+
da_codes.map {|code| EUCountry[code] }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/eu_countries.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
describe ISO3166::EUCountry do
|
4
|
+
|
5
|
+
it "should inherit from ISO3166::Country" do
|
6
|
+
ISO3166::EUCountry.superclass.should == ISO3166::Country
|
7
|
+
end
|
8
|
+
|
9
|
+
it { ISO3166::EUCountry.should respond_to(:codes) }
|
10
|
+
describe ".codes" do
|
11
|
+
it "should return an array" do
|
12
|
+
ISO3166::EUCountry.codes.should be_a_kind_of(Array)
|
13
|
+
end
|
14
|
+
it "should have the 27 member states" do
|
15
|
+
ISO3166::EUCountry.codes.should have(27).member_states
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it { ISO3166::EUCountry.should respond_to(:all) }
|
20
|
+
describe ".all" do
|
21
|
+
it "should return an array" do
|
22
|
+
ISO3166::EUCountry.all.should be_a_kind_of(Array)
|
23
|
+
end
|
24
|
+
it "should return EUCountry instances" do
|
25
|
+
ISO3166::EUCountry.all.each do |country|
|
26
|
+
country.should be_a_kind_of(ISO3166::EUCountry)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe ":except" do
|
30
|
+
context "with a single country" do
|
31
|
+
it "should return all but that one country" do
|
32
|
+
result = ISO3166::EUCountry.all :except => "GB"
|
33
|
+
result.each do |country|
|
34
|
+
country.alpha2.should_not == "GB"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "with an array of countries" do
|
39
|
+
it "should return all but those countries" do
|
40
|
+
excluded = %w(AT BE BG CY CZ DK EE FI FR DE GB)
|
41
|
+
result = ISO3166::EUCountry.all :except => excluded
|
42
|
+
result.size.should == (27-excluded.size)
|
43
|
+
result.each do |country|
|
44
|
+
excluded.should_not include(country.alpha2)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eu_countries
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Caius Durling
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-28 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: countries
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rspec
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
description: List all countries in the EU
|
57
|
+
email:
|
58
|
+
- caius@brightbox.co.uk
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
extra_rdoc_files: []
|
64
|
+
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- .rspec
|
68
|
+
- Gemfile
|
69
|
+
- Rakefile
|
70
|
+
- Readme.md
|
71
|
+
- eu_countries.gemspec
|
72
|
+
- lib/eu_countries.rb
|
73
|
+
- lib/eu_countries/eu_country.rb
|
74
|
+
- lib/eu_countries/version.rb
|
75
|
+
- spec/lib/eu_countries_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: ""
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: List all countries in the EU
|
107
|
+
test_files:
|
108
|
+
- spec/lib/eu_countries_spec.rb
|
109
|
+
- spec/spec_helper.rb
|