europe 0.0.2 → 0.0.3

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: 7a80497a0e772894b6f841f5f405f3017bdb703f
4
- data.tar.gz: 3638acd78b84722fa754064a95fadea8571c355a
3
+ metadata.gz: 1988661d9baa8aa81157d3410e0594db756f5c26
4
+ data.tar.gz: c3d31136673ace601aaff0cf31f4738ab8444208
5
5
  SHA512:
6
- metadata.gz: 0736e6a93690664d14cdbcc60524c6ec68816727906c6d4f62c3568fe683190d32245b1377ea8438906cb637a4fd8907b351ec38080f69e31485333b0bb40f23
7
- data.tar.gz: 77ad3b9b0f97b0319510687dba656cbe99690589f2d7783b54b8dc1f9634bffcc0972a72468443f173995133efe43867be4f3860a644a442d52af06482959213
6
+ metadata.gz: c9db83e2b89a39d0b5899ae26d51673f15edf98bc56b0f3d84d27648eb0f322b52cd26a33bf7e85c27f084656e365e92b4f7d5cd0e2296a2d30f95ec135c5a0e
7
+ data.tar.gz: b1b32e3e0b6bf72e9f49c5532bc1648f505d50f10718a412901fda44293caab8e0401702c061980ce1bdf2323e0aeaaf24c706cf92475d7526eea467bc57773a
data/README.md CHANGED
@@ -103,20 +103,28 @@ Europe::Countries::COUNTRIES
103
103
  ```
104
104
  Response
105
105
  ```ruby
106
- { :BE=>{
107
- :name=>"Belgium",
108
- :source_name=>"Belgique/België",
109
- :official_name=>"Kingdom of Belgium" },
110
- :BG=>{
111
- :name=>"Bulgaria",
112
- :source_name=>"България",
113
- :official_name=>"Republic of Bulgaria" },
106
+ {
107
+ :BE=>
108
+ {:name=>"Belgium",
109
+ :source_name=>"Belgique/België",
110
+ :official_name=>"Kingdom of Belgium",
111
+ :tld=>".be",
112
+ :currency=>:EUR,
113
+ :capital=>"Brussels"},
114
+ :BG=>
115
+ {:name=>"Bulgaria",
116
+ :source_name=>"България",
117
+ :official_name=>"Republic of Bulgaria",
118
+ :tld=>".bg",
119
+ :currency=>:BGN,
120
+ :capital=>"Sofia"},
121
+ ...
114
122
  ```
115
123
 
116
124
  ## Retrieving country information reversed
117
- Call
125
+ Call with optional parameters (name, currency, source_name, official_name, tld, currency and capital)
118
126
  ```ruby
119
- Europe::Countries.name_to_code
127
+ Europe::Countries::Reversed.generate('name')
120
128
  ```
121
129
  Response
122
130
  ```ruby
@@ -126,6 +134,7 @@ Response
126
134
  "Denmark" => :DK,
127
135
  "Germany" => :DE,
128
136
  "Estonia" => :EE,
137
+ ...
129
138
  ```
130
139
 
131
140
  ## Compatibility
@@ -136,9 +145,9 @@ This gem is tested with the following Ruby versions on Linux and Mac OS X:
136
145
 
137
146
  ## Todo
138
147
 
139
- - Add more country information
148
+ - ~~VAT number format validation (http://ec.europa.eu/taxation_customs/vies/faqvies.do#item11)~~
149
+ - ~~Add more country information~~
140
150
  - Eurostat integration (http://ec.europa.eu/eurostat/)
141
- - ~~ VAT number format validation (http://ec.europa.eu/taxation_customs/vies/faqvies.do#item11)~~
142
151
  - ..
143
152
 
144
153
  ## Contributing
@@ -147,4 +156,4 @@ This gem is tested with the following Ruby versions on Linux and Mac OS X:
147
156
  2. Create your feature branch (`git checkout -b my-new-feature`)
148
157
  3. Commit your changes (`git commit -am 'Add some feature'`)
149
158
  4. Push to the branch (`git push origin my-new-feature`)
150
- 5. Create a new Pull Request
159
+ 5. Create a new Pull Request
@@ -8,12 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Europe::VERSION
9
9
  spec.authors = ['VvanGemert']
10
10
  spec.email = ['vincent@floorplanner.com']
11
- spec.summary = 'Europe is a gem for retrieving and validating \
12
- EU government data.'
13
- spec.description = 'Europe is a simple library for retrieving \
14
- EU government data such as VAT information, \
15
- VAT validation, currency exchange rates and \
16
- country information.'
11
+ spec.summary = 'Europe is a gem for retrieving and validating' \
12
+ 'EU government data.'
13
+ spec.description = 'Europe is a simple library for retrieving ' \
14
+ 'EU government data such as VAT information, ' \
15
+ 'VAT validation, currency exchange rates and' \
16
+ 'country information.'
17
17
  spec.homepage = 'https://github.com/VvanGemert/europe'
18
18
  spec.license = 'MIT'
19
19
 
@@ -2,6 +2,7 @@ require 'europe/version'
2
2
  require 'europe/countries/countries'
3
3
  require 'europe/currency/currency'
4
4
  require 'europe/vat/vat'
5
+ require 'europe/eurostat/eurostat'
5
6
 
6
7
  # Europe Gem
7
8
  module Europe
@@ -3,101 +3,97 @@
3
3
 
4
4
  # Source: http://publications.europa.eu/code/pdf/370000en.htm
5
5
 
6
+ require 'europe/countries/reversed'
7
+
6
8
  # Europe Gem
7
9
  module Europe
8
10
  # Countries
9
11
  module Countries
10
12
  COUNTRIES = {
11
- BE: { name: 'Belgium',
12
- source_name: 'Belgique/België',
13
- official_name: 'Kingdom of Belgium' },
14
- BG: { name: 'Bulgaria',
15
- source_name: 'България',
16
- official_name: 'Republic of Bulgaria' },
17
- CZ: { name: 'Czech Republic',
18
- source_name: 'Česká republika',
19
- official_name: 'Czech Republic' },
20
- DK: { name: 'Denmark',
21
- source_name: 'Danmark',
22
- official_name: 'Kingdom of Denmark' },
23
- DE: { name: 'Germany',
24
- source_name: 'Deutschland',
25
- official_name: 'Federal Republic of Germany' },
26
- EE: { name: 'Estonia',
27
- source_name: 'Eesti',
28
- official_name: 'Republic of Estonia' },
29
- IE: { name: 'Ireland',
30
- source_name: 'Éire',
31
- official_name: 'Ireland' },
32
- EL: { name: 'Greece',
33
- source_name: 'Ελλάδα',
34
- official_name: 'Hellenic Republic' },
35
- ES: { name: 'Spain',
36
- source_name: 'España',
37
- official_name: 'Kingdom of Spain' },
38
- FR: { name: 'France',
39
- source_name: 'France',
40
- official_name: 'French Republic' },
41
- HR: { name: 'Croatia',
42
- source_name: 'Hrvatska',
43
- official_name: 'Republic of Croatia' },
44
- IT: { name: 'Italy',
45
- source_name: 'Italia',
46
- official_name: 'Italian Republic' },
47
- CY: { name: 'Cyprus',
48
- source_name: 'Κύπρος',
49
- official_name: 'Republic of Cyprus' },
50
- LV: { name: 'Latvia',
51
- source_name: 'Latvija',
52
- official_name: 'Republic of Latvia' },
53
- LT: { name: 'Lithuania',
54
- source_name: 'Lietuva',
55
- official_name: 'Republic of Lithuania' },
56
- LU: { name: 'Luxembourg',
57
- source_name: 'Luxembourg',
58
- official_name: 'Grand Duchy of Luxembourg' },
59
- HU: { name: 'Hungary',
60
- source_name: 'Magyarország',
61
- official_name: 'Hungary' },
62
- MT: { name: 'Malta',
63
- source_name: 'Malta',
64
- official_name: 'Republic of Malta' },
65
- NL: { name: 'Netherlands',
66
- source_name: 'Nederland',
67
- official_name: 'Kingdom of the Netherlands' },
68
- AT: { name: 'Austria',
69
- source_name: 'Österreich',
70
- official_name: 'Republic of Austria' },
71
- PL: { name: 'Poland',
72
- source_name: 'Polska',
73
- official_name: 'Republic of Poland' },
74
- PT: { name: 'Portugal',
75
- source_name: 'Portugal',
76
- official_name: 'Portuguese Republic' },
77
- RO: { name: 'Romania',
78
- source_name: 'România',
79
- official_name: 'Romania' },
80
- SI: { name: 'Slovenia',
81
- source_name: 'Slovenija',
82
- official_name: 'Republic of Slovenia' },
83
- SK: { name: 'Slovak Republic',
84
- source_name: 'Slovensko',
85
- official_name: 'Slovak Republic' },
86
- FI: { name: 'Finland',
87
- source_name: 'Suomi',
88
- official_name: 'Republic of Finland' },
89
- SE: { name: 'Sweden',
90
- source_name: 'Sverige',
91
- official_name: 'Kingdom of Sweden' },
92
- UK: { name: 'United Kingdom',
93
- source_name: 'United Kingdom',
13
+ BE: { name: 'Belgium', source_name: 'Belgique/België',
14
+ official_name: 'Kingdom of Belgium',
15
+ tld: '.be', currency: :EUR, capital: 'Brussels' },
16
+ BG: { name: 'Bulgaria', source_name: 'България',
17
+ official_name: 'Republic of Bulgaria',
18
+ tld: '.bg', currency: :BGN, capital: 'Sofia' },
19
+ CZ: { name: 'Czech Republic', source_name: 'Česká republika',
20
+ official_name: 'Czech Republic',
21
+ tld: '.cz', currency: :CZK, capital: 'Prague' },
22
+ DK: { name: 'Denmark', source_name: 'Danmark',
23
+ official_name: 'Kingdom of Denmark',
24
+ tld: '.dk', currency: :DKK, capital: 'Copenhagen' },
25
+ DE: { name: 'Germany', source_name: 'Deutschland',
26
+ official_name: 'Federal Republic of Germany',
27
+ tld: '.de', currency: :EUR, capital: 'Berlin' },
28
+ EE: { name: 'Estonia', source_name: 'Eesti',
29
+ official_name: 'Republic of Estonia',
30
+ tld: '.ee', currency: :EUR, capital: 'Tallinn' },
31
+ IE: { name: 'Ireland', source_name: 'Éire',
32
+ official_name: 'Ireland',
33
+ tld: '.ie', currency: :EUR, capital: 'Dublin' },
34
+ EL: { name: 'Greece', source_name: 'Ελλάδα',
35
+ official_name: 'Hellenic Republic',
36
+ tld: '.gr', currency: :EUR, capital: 'Athens' },
37
+ ES: { name: 'Spain', source_name: 'España',
38
+ official_name: 'Kingdom of Spain',
39
+ tld: '.es', currency: :EUR, capital: 'Madrid' },
40
+ FR: { name: 'France', source_name: 'France',
41
+ official_name: 'French Republic',
42
+ tld: '.fr', currency: :EUR, capital: 'Paris' },
43
+ HR: { name: 'Croatia', source_name: 'Hrvatska',
44
+ official_name: 'Republic of Croatia',
45
+ tld: '.hr', currency: :HRK, capital: 'Zagreb' },
46
+ IT: { name: 'Italy', source_name: 'Italia',
47
+ official_name: 'Italian Republic',
48
+ tld: '.it', currency: :EUR, capital: 'Rome' },
49
+ CY: { name: 'Cyprus', source_name: 'Κύπρος',
50
+ official_name: 'Republic of Cyprus',
51
+ tld: '.cy', currency: :EUR, capital: 'Nicosia' },
52
+ LV: { name: 'Latvia', source_name: 'Latvija',
53
+ official_name: 'Republic of Latvia',
54
+ tld: '.lv', currency: :EUR, capital: 'Riga' },
55
+ LT: { name: 'Lithuania', source_name: 'Lietuva',
56
+ official_name: 'Republic of Lithuania',
57
+ tld: '.lt', currency: :EUR, capital: 'Vilnius' },
58
+ LU: { name: 'Luxembourg', source_name: 'Luxembourg',
59
+ official_name: 'Grand Duchy of Luxembourg',
60
+ tld: '.lu', currency: :EUR, capital: 'Luxembourg City' },
61
+ HU: { name: 'Hungary', source_name: 'Magyarország',
62
+ official_name: 'Hungary',
63
+ tld: '.hu', currency: :HUF, capital: 'Budapest' },
64
+ MT: { name: 'Malta', source_name: 'Malta',
65
+ official_name: 'Republic of Malta',
66
+ tld: '.mt', currency: :EUR, capital: 'Valletta' },
67
+ NL: { name: 'Netherlands', source_name: 'Nederland',
68
+ official_name: 'Kingdom of the Netherlands',
69
+ tld: '.nl', currency: :EUR, capital: 'Amsterdam' },
70
+ AT: { name: 'Austria', source_name: 'Österreich',
71
+ official_name: 'Republic of Austria',
72
+ tld: '.at', currency: :EUR, capital: 'Vienna' },
73
+ PL: { name: 'Poland', source_name: 'Polska',
74
+ official_name: 'Republic of Poland',
75
+ tld: '.pl', currency: :PLN, capital: 'Warsaw' },
76
+ PT: { name: 'Portugal', source_name: 'Portugal',
77
+ official_name: 'Portuguese Republic',
78
+ tld: '.pt', currency: :EUR, capital: 'Lisbon' },
79
+ RO: { name: 'Romania', source_name: 'România',
80
+ official_name: 'Romania',
81
+ tld: '.ro', currency: :RON, capital: 'Bucharest' },
82
+ SI: { name: 'Slovenia', source_name: 'Slovenija',
83
+ official_name: 'Republic of Slovenia',
84
+ tld: '.si', currency: :EUR, capital: 'Ljubljana' },
85
+ SK: { name: 'Slovak Republic', source_name: 'Slovensko',
86
+ official_name: 'Slovak Republic',
87
+ tld: '.sk', currency: :EUR, capital: 'Bratislava' },
88
+ FI: { name: 'Finland', source_name: 'Suomi',
89
+ official_name: 'Republic of Finland',
90
+ tld: '.fi', currency: :EUR, capital: 'Helsinki' },
91
+ SE: { name: 'Sweden', source_name: 'Sverige',
92
+ official_name: 'Kingdom of Sweden',
93
+ tld: '.se', currency: :EUR, capital: 'Stockholm' },
94
+ UK: { name: 'United Kingdom', source_name: 'United Kingdom',
94
95
  official_name: 'United Kingdom of Great ' \
95
- 'Britain and Northern Ireland' } }
96
-
97
- def self.name_to_code
98
- @name_to_code ||= COUNTRIES.each_with_object({}) do |(key, value), out|
99
- out[value[:name]] = key
100
- end
101
- end
96
+ 'Britain and Northern Ireland',
97
+ tld: '.uk', currency: :GBP, capital: 'London' } }
102
98
  end
103
99
  end
@@ -0,0 +1,32 @@
1
+ module Europe
2
+ # Countries
3
+ module Countries
4
+ # Reversed
5
+ module Reversed
6
+ def self.generate(country_value)
7
+ COUNTRIES.each_with_object({}) do |(key, value), out|
8
+ reverse_handle_value(out, key, value, country_value)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def self.reverse_handle_value(out, key, value, country_value)
15
+ if out[value[country_value.to_sym]]
16
+ reverse_handle_array(out, key, value, country_value)
17
+ else
18
+ out[value[country_value.to_sym]] = key
19
+ end
20
+ end
21
+
22
+ def self.reverse_handle_array(out, key, value, country_value)
23
+ if out[value[country_value.to_sym]].is_a?(Array)
24
+ out[value[country_value.to_sym]] << key
25
+ else
26
+ out[value[country_value.to_sym]] =
27
+ [out[value[country_value.to_sym]], key]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ # Europe Gem
6
+ module Europe
7
+ # Eurostat
8
+ module Eurostat
9
+ STAT_URL = 'http://ec.europa.eu/eurostat/wdds' \
10
+ '/rest/data/v1.1/json/en/'
11
+
12
+ def self.retrieve(dataset, filters)
13
+ fetch_stats(dataset, filters)
14
+ end
15
+
16
+ private
17
+
18
+ def self.generate_url(dataset, _filters)
19
+ uri = URI.parse(STAT_URL + dataset)
20
+ params = {
21
+ precision: 1, geo: 'EU28',
22
+ unit: 'EUR_HAB', time: '2010',
23
+ indic_na: 'B1GM', unitLabel: 'code' }
24
+ uri.query = URI.encode_www_form(params)
25
+ uri
26
+ end
27
+
28
+ def self.fetch_stats(dataset, filters)
29
+ uri = generate_url(dataset, filters)
30
+ resp = Net::HTTP.get(uri)
31
+ JSON.parse(resp)
32
+ end
33
+ end
34
+ end
@@ -17,7 +17,8 @@ module Europe
17
17
  private
18
18
 
19
19
  def self.extract_country_code(data)
20
- Europe::Countries.name_to_code[data.css('td').first.text.strip!]
20
+ Europe::Countries::Reversed.generate(:name) \
21
+ [data.css('td').first.text.strip!]
21
22
  end
22
23
 
23
24
  def self.extract_rate_number(data)
@@ -1,4 +1,4 @@
1
1
  # Europe version
2
2
  module Europe
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
@@ -7,7 +7,8 @@ module Europe
7
7
  include Benchmark
8
8
 
9
9
  def test_country_by_name
10
- reversed_hash = Europe::Countries.name_to_code
10
+ reversed_hash =
11
+ Europe::Countries::Reversed.generate(:name)
11
12
  assert_equal reversed_hash['Netherlands'], :NL
12
13
  assert_equal reversed_hash['Ireland'], :IE
13
14
  end
@@ -14,7 +14,8 @@ module Europe
14
14
  def test_validation_of_correct_vat_number
15
15
  # PostNL
16
16
  validate_correct_vat = Europe::Vat.validate('NL', '009291477B01')
17
- assert validate_correct_vat[:valid]
17
+ assert validate_correct_vat[:valid] \
18
+ unless validate_correct_vat == :fault
18
19
 
19
20
  # Sky
20
21
  validate_correct_vat = Europe::Vat.validate('GB', '440627467')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: europe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - VvanGemert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-19 00:00:00.000000000 Z
11
+ date: 2015-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -122,11 +122,8 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: |-
126
- Europe is a simple library for retrieving \
127
- EU government data such as VAT information, \
128
- VAT validation, currency exchange rates and \
129
- country information.
125
+ description: Europe is a simple library for retrieving EU government data such as
126
+ VAT information, VAT validation, currency exchange rates andcountry information.
130
127
  email:
131
128
  - vincent@floorplanner.com
132
129
  executables: []
@@ -145,8 +142,10 @@ files:
145
142
  - europe.gemspec
146
143
  - lib/europe.rb
147
144
  - lib/europe/countries/countries.rb
145
+ - lib/europe/countries/reversed.rb
148
146
  - lib/europe/currency/currency.rb
149
147
  - lib/europe/currency/exchange_rates.rb
148
+ - lib/europe/eurostat/eurostat.rb
150
149
  - lib/europe/vat/format.rb
151
150
  - lib/europe/vat/rates.rb
152
151
  - lib/europe/vat/vat.rb
@@ -181,7 +180,7 @@ rubyforge_project:
181
180
  rubygems_version: 2.4.8
182
181
  signing_key:
183
182
  specification_version: 4
184
- summary: Europe is a gem for retrieving and validating \ EU government data.
183
+ summary: Europe is a gem for retrieving and validatingEU government data.
185
184
  test_files:
186
185
  - test/europe/countries/country_test.rb
187
186
  - test/europe/currency/currency_test.rb