europe 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de67a9a0a75909308ceba08e914998b551daa158
4
- data.tar.gz: 2f1ff149e70373a95aafb104e29b5353639aaeab
3
+ metadata.gz: 7a80497a0e772894b6f841f5f405f3017bdb703f
4
+ data.tar.gz: 3638acd78b84722fa754064a95fadea8571c355a
5
5
  SHA512:
6
- metadata.gz: cff8f406e3666c2d54a76670c6ebcad127b5a92db31b888d678983e90893fa20f7cf75d532a5d2702e0d79bf2d13f45932b0264a2514c981528da570bb549091
7
- data.tar.gz: 103b78ce13b51964788c26c6234a7d5bdfafc87d50781859e045de7485018d852725c93dea4f13795d7903eb31c631ccf78ac9c34f00c1b8a522b4388d7f747c
6
+ metadata.gz: 0736e6a93690664d14cdbcc60524c6ec68816727906c6d4f62c3568fe683190d32245b1377ea8438906cb637a4fd8907b351ec38080f69e31485333b0bb40f23
7
+ data.tar.gz: 77ad3b9b0f97b0319510687dba656cbe99690589f2d7783b54b8dc1f9634bffcc0972a72468443f173995133efe43867be4f3860a644a442d52af06482959213
@@ -4,5 +4,7 @@ cache: bundler
4
4
  rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1.8
7
8
  - 2.2.0
8
- - 2.2.3
9
+ - 2.2.3
10
+ - 2.2.4
data/README.md CHANGED
@@ -38,6 +38,17 @@ Response
38
38
  :address=>"6 CENTAURS BUSINESS PARK\nGRANT WAY\nISLEWORTH\nMIDDLESEX\n\nTW7 5QD" }
39
39
  ```
40
40
 
41
+ ### Validate VAT number format
42
+ Call
43
+ ```ruby
44
+ Europe::Vat::Format.validate('NL123456789B01')
45
+ ```
46
+ Response
47
+ ```ruby
48
+ => true
49
+ ```
50
+
51
+
41
52
  ### Retrieving VAT rates for each EC/EU member
42
53
  Call
43
54
  ```ruby
@@ -117,6 +128,19 @@ Response
117
128
  "Estonia" => :EE,
118
129
  ```
119
130
 
131
+ ## Compatibility
132
+
133
+ This gem is tested with the following Ruby versions on Linux and Mac OS X:
134
+
135
+ - Ruby MRI 1.9.3, 2.0.0, 2.1.8, 2.2.0, 2.2.3, 2.2.4
136
+
137
+ ## Todo
138
+
139
+ - Add more country information
140
+ - Eurostat integration (http://ec.europa.eu/eurostat/)
141
+ - ~~ VAT number format validation (http://ec.europa.eu/taxation_customs/vies/faqvies.do#item11)~~
142
+ - ..
143
+
120
144
  ## Contributing
121
145
 
122
146
  1. Fork it ( https://github.com/VvanGemert/europe/fork )
@@ -8,10 +8,13 @@ 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 helper gem for retrieving \
12
- EU government data'
13
- spec.description = 'This gem retrieves data from EU government websites'
14
- spec.homepage = ''
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
+ spec.homepage = 'https://github.com/VvanGemert/europe'
15
18
  spec.license = 'MIT'
16
19
 
17
20
  spec.files = `git ls-files -z`.split("\x0")
@@ -27,4 +30,5 @@ Gem::Specification.new do |spec|
27
30
  spec.add_development_dependency 'minitest'
28
31
  spec.add_development_dependency 'awesome_print'
29
32
  spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'rubocop'
30
34
  end
@@ -0,0 +1,52 @@
1
+ # Europe Gem
2
+ module Europe
3
+ # VAT
4
+ module Vat
5
+ # Format
6
+ module Format
7
+ VAT_REGEX = {
8
+ AT: /^ATU\d{8}$/,
9
+ BE: /^BE0\d{9}$/,
10
+ BG: /^BG(\d{10}|\d{9})$/,
11
+ CY: /^CY\d{8}[A-Z]$/,
12
+ CZ: /^CZ(\d{8}|\d{9}|\d{10})$/,
13
+ DE: /^DE\d{9}$/,
14
+ DK: /^DK\d{2} \d{2} \d{2} \d{2}$/,
15
+ EE: /^EE\d{9}$/,
16
+ EL: /^EL\d{9}$/,
17
+ ES: /^ES([A-Z0-9]\d{7}[A-Z0-9])$/,
18
+ FI: /^FI\d{8}$/,
19
+ FR: /^FR[A-Z0-9][A-Z0-9] \d{9}$/,
20
+ GB: [/^GB(\d{3} \d{4} \d{2}( \d{3}5)?)$/, /^GB(HA|GD)\d{3}(6|7)$/],
21
+ HR: /^HR\d{11}$/,
22
+ HU: /^HU\d{8}$/,
23
+ IE: /^IE\d[A-Z0-9\+\*|\d]\d{5}([A-Z]|WI)$/,
24
+ IT: /^IT\d{11}$/,
25
+ LT: /^LT(\d{9}|\d{12})$/,
26
+ LU: /^LU\d{8}$/,
27
+ LV: /^LV\d{11}$/,
28
+ MT: /^MT\d{8}$/,
29
+ NL: /^NL\d{9}B\d\d$/,
30
+ PL: /^PL\d{10}$/,
31
+ PT: /^PT\d{9}$/,
32
+ RO: /^RO\d{2,10}$/,
33
+ SE: /^SE\d{12}$/,
34
+ SI: /^SI\d{8}$/,
35
+ SK: /^SK\d{10}$/
36
+ }
37
+
38
+ def self.validate(number)
39
+ country_code = number[0..1].to_sym
40
+ return false unless VAT_REGEX.keys.include?(country_code)
41
+ if VAT_REGEX[country_code.to_sym].is_a?(Array)
42
+ VAT_REGEX[country_code.to_sym].each do |regex|
43
+ return true if regex.match(number)
44
+ end
45
+ else
46
+ return true if VAT_REGEX[country_code.to_sym].match(number)
47
+ end
48
+ false
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,4 +1,5 @@
1
1
  require 'europe/vat/rates'
2
+ require 'europe/vat/format'
2
3
  require 'savon'
3
4
 
4
5
  # Europe Gem
@@ -1,4 +1,4 @@
1
1
  # Europe version
2
2
  module Europe
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module Europe
4
4
  module Countries
5
- # CurrencyTest
5
+ # CountryTest
6
6
  class CountryTest < Minitest::Test
7
7
  include Benchmark
8
8
 
@@ -2,14 +2,12 @@ require 'test_helper'
2
2
 
3
3
  module Europe
4
4
  module Currency
5
- # CurrencyTest
5
+ # ExchangeRatesTest
6
6
  class ExchangeRatesTest < Minitest::Test
7
7
  include Benchmark
8
8
 
9
9
  def test_retrieval_exchange_rates
10
10
  rates = Europe::Currency::ExchangeRates.retrieve
11
- assert_equal rates[:date].to_s,
12
- DateTime.now.strftime('%Y-%m-%d')
13
11
  assert rates[:rates].keys.include?(:GBP)
14
12
  end
15
13
  end
@@ -0,0 +1,97 @@
1
+ require 'test_helper'
2
+
3
+ module Europe
4
+ module Vat
5
+ # FormatTest
6
+ class FormatTest < Minitest::Test
7
+ include Benchmark
8
+
9
+ VAT_FORMAT_VALIDATION = {
10
+ AT: 'ATU99999999',
11
+ BE: 'BE0999999999',
12
+ BG: %w(BG999999999 BG9999999999),
13
+ CY: 'CY99999999L',
14
+ CZ: %w(CZ99999999 CZ999999999 CZ9999999999),
15
+ DE: 'DE999999999',
16
+ DK: 'DK99 99 99 99',
17
+ EE: 'EE999999999',
18
+ EL: 'EL999999999',
19
+ ES: 'ESX9999999X',
20
+ FI: 'FI99999999',
21
+ FR: 'FRXX 999999999',
22
+ GB: ['GB999 9999 99 9995',
23
+ 'GBGD9996',
24
+ 'GBHA9997',
25
+ 'GB999 9999 99'],
26
+ HR: 'HR99999999999',
27
+ HU: 'HU99999999',
28
+ IE: %w(IE9S99999L IE9999999WI),
29
+ IT: 'IT99999999999',
30
+ LT: %w(LT999999999 LT999999999999),
31
+ LU: 'LU99999999',
32
+ LV: 'LV99999999999',
33
+ MT: 'MT99999999',
34
+ NL: 'NL999999999B99',
35
+ PL: 'PL9999999999',
36
+ PT: 'PT999999999',
37
+ RO: 'RO999999999',
38
+ SE: 'SE999999999999',
39
+ SI: 'SI99999999',
40
+ SK: 'SK9999999999' }
41
+
42
+ def test_all_vat_numbers_on_format
43
+ VAT_FORMAT_VALIDATION.each do |_country, number|
44
+ if number.is_a?(Array)
45
+ number.each do |num|
46
+ check_vat_number(num)
47
+ end
48
+ else
49
+ check_vat_number(number)
50
+ end
51
+ end
52
+ end
53
+
54
+ def check_vat_number(number)
55
+ check_true_values(number)
56
+ check_character_and_digit(number) \
57
+ if number[2..-1].include?('X')
58
+ check_integer(number) if number[2..-1].include?('9')
59
+ check_alphanumeric(number) if number[2..-1].include?('L')
60
+ check_false_values(number)
61
+ end
62
+
63
+ def check_character_and_digit(number)
64
+ assert_equal true, Europe::Vat::Format.validate(
65
+ number[0..1] +
66
+ number[2..-1].gsub(/X/, [*('A'..'Z'), *('0'..'9')].sample))
67
+ end
68
+
69
+ def check_integer(number)
70
+ { number[0..1] + number[2..-1].gsub(/9/, [*('0'..'9')].sample) => true,
71
+ number.gsub(/9/, rand(10).to_s) => true,
72
+ number.gsub(/9/, [*('A'..'Z')].sample(1).join) => false
73
+ }.each do |key, value|
74
+ assert_equal value, Europe::Vat::Format.validate(key)
75
+ end
76
+ end
77
+
78
+ def check_alphanumeric(number)
79
+ assert_equal true, Europe::Vat::Format.validate(
80
+ number[0..1] + number[2..-1].gsub(/L/, [*('A'..'Z')].sample))
81
+ assert_equal false, Europe::Vat::Format.validate(
82
+ number[0..1] + number[2..-1].gsub(/L/, [*('0'..'9')].sample))
83
+ end
84
+
85
+ def check_true_values(number)
86
+ assert_equal true, Europe::Vat::Format.validate(number)
87
+ end
88
+
89
+ def check_false_values(number)
90
+ assert_equal false, Europe::Vat::Format.validate(
91
+ number + [*('A'..'Z'), *('0'..'9')].sample(3).join)
92
+ assert_equal false, Europe::Vat::Format.validate(
93
+ [*('A'..'Z'), *('0'..'9')].sample + number)
94
+ end
95
+ end
96
+ end
97
+ end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module Europe
4
4
  module Vat
5
- # CurrencyTest
5
+ # RatesTest
6
6
  class RatesTest < Minitest::Test
7
7
  include Benchmark
8
8
 
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module Europe
4
4
  module Vat
5
- # CurrencyTest
5
+ # ValidationTest
6
6
  class ValidationTest < Minitest::Test
7
7
  include Benchmark
8
8
 
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.1
4
+ version: 0.0.2
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-15 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -108,7 +108,25 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: This gem retrieves data from EU government websites
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
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.
112
130
  email:
113
131
  - vincent@floorplanner.com
114
132
  executables: []
@@ -129,16 +147,18 @@ files:
129
147
  - lib/europe/countries/countries.rb
130
148
  - lib/europe/currency/currency.rb
131
149
  - lib/europe/currency/exchange_rates.rb
150
+ - lib/europe/vat/format.rb
132
151
  - lib/europe/vat/rates.rb
133
152
  - lib/europe/vat/vat.rb
134
153
  - lib/europe/version.rb
135
154
  - test/europe/countries/country_test.rb
136
155
  - test/europe/currency/currency_test.rb
137
156
  - test/europe/currency/exchange_rates_test.rb
157
+ - test/europe/vat/format_test.rb
138
158
  - test/europe/vat/rates_test.rb
139
159
  - test/europe/vat/validation_test.rb
140
160
  - test/test_helper.rb
141
- homepage: ''
161
+ homepage: https://github.com/VvanGemert/europe
142
162
  licenses:
143
163
  - MIT
144
164
  metadata: {}
@@ -161,11 +181,12 @@ rubyforge_project:
161
181
  rubygems_version: 2.4.8
162
182
  signing_key:
163
183
  specification_version: 4
164
- summary: Europe is a helper gem for retrieving \ EU government data
184
+ summary: Europe is a gem for retrieving and validating \ EU government data.
165
185
  test_files:
166
186
  - test/europe/countries/country_test.rb
167
187
  - test/europe/currency/currency_test.rb
168
188
  - test/europe/currency/exchange_rates_test.rb
189
+ - test/europe/vat/format_test.rb
169
190
  - test/europe/vat/rates_test.rb
170
191
  - test/europe/vat/validation_test.rb
171
192
  - test/test_helper.rb