europe 0.0.19 → 0.0.21
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 +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/lib/europe/vat/rates.rb +16 -3
- data/lib/europe/vat/vat.rb +2 -0
- data/lib/europe/version.rb +1 -1
- data/test/europe/vat/format_test.rb +6 -6
- data/test/europe/vat/rates_test.rb +3 -5
- data/test/europe/vat/validation_test.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1265263ae93ea1408b778a1bff21d44a913d54f10e034d2eb4f2536ed3e87ce
|
4
|
+
data.tar.gz: '079be0aeba6bf84a543b9df49e25d1571b3a8527b3770c176ae3014b3260d809'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb51a61ff49138ce79b0e3919427967a62b79ece0f8285c3b2074cbb4cb2a960f02d611970991e43784dcb750e09d8708c822840b338cbd41cd3aa1c5df53666
|
7
|
+
data.tar.gz: 8c4eda6745c2a60a39e9c38dbb2770a23cf0597764bfab1e57deeac3c2bdbcbf5fe0659c0a96cf023176219808ccab0c91966d4e8454a1f0632f9c91eda61f02
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
## 0.0.21
|
5
|
+
- Added check to fail short VAT numbers under 5 characters
|
6
|
+
- [Full Changelog](https://github.com/gem-shards/europe.rb/compare/v0.0.20...v0.0.21)
|
7
|
+
## 0.0.20
|
8
|
+
- Added fallback VAT rates in case the EU website is down or unresponsive
|
9
|
+
- [Full Changelog](https://github.com/gem-shards/europe.rb/compare/v0.0.19...v0.0.20)
|
4
10
|
## 0.0.19
|
5
11
|
- Fixed VAT validation call because XML response was updated
|
6
12
|
- [Full Changelog](https://github.com/gem-shards/europe.rb/compare/v0.0.18...v0.0.19)
|
data/lib/europe/vat/rates.rb
CHANGED
@@ -6,21 +6,33 @@ module Europe
|
|
6
6
|
module Vat
|
7
7
|
# Rates
|
8
8
|
module Rates
|
9
|
+
FALLBACK_RATES = {
|
10
|
+
AT: 20.0, BE: 21.0, BG: 20.0, CY: 19.0, CZ: 21.0, DE: 19.0, DK: 25.0, EE: 20.0,
|
11
|
+
EL: 24.0, ES: 21.0, FI: 24.0, FR: 20.0, UK: 20.0, HR: 25.0, HU: 27.0, IE: 23.0,
|
12
|
+
IT: 22.0, LT: 21.0, LU: 17.0, LV: 21.0, MT: 18.0, NL: 21.0, PL: 23.0, PT: 23.0,
|
13
|
+
RO: 19.0, SE: 25.0, SI: 22.0, SK: 20.0
|
14
|
+
}.freeze
|
9
15
|
RATES_URL = 'https://ec.europa.eu/taxation_customs/' \
|
10
16
|
'business/vat/telecommunications-broadcasting' \
|
11
17
|
'-electronic-services/vat-rates_en'
|
12
18
|
|
13
19
|
def self.retrieve
|
14
20
|
resp = fetch_rates
|
15
|
-
return
|
21
|
+
return FALLBACK_RATES if resp.nil?
|
16
22
|
|
17
23
|
extract_rates(resp)
|
18
24
|
end
|
19
25
|
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
20
27
|
def self.extract_rates(resp)
|
21
28
|
rates = {}
|
22
29
|
|
23
|
-
|
30
|
+
begin
|
31
|
+
data = resp.scan(%r{\<tbody\>(.*)\<\/tbody\>}m).first.first.strip
|
32
|
+
rescue NoMethodError
|
33
|
+
return FALLBACK_RATES
|
34
|
+
end
|
35
|
+
|
24
36
|
xml = REXML::Document.new("<root>#{data}</root>")
|
25
37
|
xml.first.elements.each('tr') do |result|
|
26
38
|
next if result[3].nil?
|
@@ -29,6 +41,7 @@ module Europe
|
|
29
41
|
end
|
30
42
|
rates
|
31
43
|
end
|
44
|
+
# rubocop:enable Metrics/MethodLength
|
32
45
|
|
33
46
|
def self.filter_rate(result, rates)
|
34
47
|
country = result[0].text
|
@@ -40,7 +53,7 @@ module Europe
|
|
40
53
|
|
41
54
|
def self.fetch_rates
|
42
55
|
resp = Net::HTTP.get_response(URI.parse(RATES_URL))
|
43
|
-
resp.code.to_i == 200 ? resp.body :
|
56
|
+
resp.code.to_i == 200 ? resp.body : nil
|
44
57
|
end
|
45
58
|
end
|
46
59
|
end
|
data/lib/europe/vat/vat.rb
CHANGED
@@ -33,6 +33,8 @@ module Europe
|
|
33
33
|
XML
|
34
34
|
|
35
35
|
def self.validate(number)
|
36
|
+
return :failed if number.size < 4
|
37
|
+
|
36
38
|
response = send_request(number[0..1], number[2..-1])
|
37
39
|
return :failed unless response.is_a? Net::HTTPSuccess
|
38
40
|
return :failed if response.body.include?('soap:Fault')
|
data/lib/europe/version.rb
CHANGED
@@ -62,15 +62,15 @@ module Europe
|
|
62
62
|
def check_character_and_digit(number)
|
63
63
|
assert_equal true, Europe::Vat::Format.validate(
|
64
64
|
number[0..1] +
|
65
|
-
number[2..-1].gsub(
|
65
|
+
number[2..-1].gsub('X', [*('A'..'Z'), *('0'..'9')].sample)
|
66
66
|
)
|
67
67
|
end
|
68
68
|
|
69
69
|
def check_integer(number)
|
70
70
|
{
|
71
|
-
number[0..1] + number[2..-1].gsub(
|
72
|
-
number.gsub(
|
73
|
-
number.gsub(
|
71
|
+
number[0..1] + number[2..-1].gsub('9', [*('0'..'9')].sample) => true,
|
72
|
+
number.gsub('9', rand(10).to_s) => true,
|
73
|
+
number.gsub('9', [*('A'..'Z')].sample(1).join) => false
|
74
74
|
}.each do |key, value|
|
75
75
|
assert_equal value, Europe::Vat::Format.validate(key)
|
76
76
|
end
|
@@ -78,10 +78,10 @@ module Europe
|
|
78
78
|
|
79
79
|
def check_alphanumeric(number)
|
80
80
|
assert_equal true, Europe::Vat::Format.validate(
|
81
|
-
number[0..1] + number[2..-1].gsub(
|
81
|
+
number[0..1] + number[2..-1].gsub('L', [*('A'..'Z')].sample)
|
82
82
|
)
|
83
83
|
assert_equal false, Europe::Vat::Format.validate(
|
84
|
-
number[0..1] + number[2..-1].gsub(
|
84
|
+
number[0..1] + number[2..-1].gsub('L', [*('0'..'9')].sample)
|
85
85
|
)
|
86
86
|
end
|
87
87
|
|
@@ -14,11 +14,9 @@ module Europe
|
|
14
14
|
|
15
15
|
def test_retrieval_of_vat_rates
|
16
16
|
rates = Europe::Vat::Rates.retrieve
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
assert_equal rates.count, Europe::Countries::COUNTRIES.count
|
21
|
-
end
|
17
|
+
|
18
|
+
assert_equal rates.count, Europe::Countries::COUNTRIES.count
|
19
|
+
|
22
20
|
assert rates[:NL]
|
23
21
|
assert rates[:DE]
|
24
22
|
assert rates[:ES]
|
@@ -12,6 +12,10 @@ module Europe
|
|
12
12
|
WebMock.disable!
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_validation_of_short_vat_number
|
16
|
+
assert_equal :failed, Europe::Vat.validate('6')
|
17
|
+
end
|
18
|
+
|
15
19
|
def test_validation_of_false_vat_number
|
16
20
|
validate_false_vat = Europe::Vat.validate('NL123456789B01')
|
17
21
|
assert_equal false, validate_false_vat[:valid]
|
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.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gem shards
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|