company_number 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 4730b631eea536093350f53559626fb2ed03dd1ca63fb31169a5c9c0e0a1b1c7
4
- data.tar.gz: 555444d1b274831d7bb4a2476af3d173976c59b9f44894d78198e427d88fa755
3
+ metadata.gz: 0d4b40991721f4eb047e7060a428f3d85593cc4ce3dd15bb427d95ed629cbb37
4
+ data.tar.gz: cfedbc59ad70b411b385ba55813e5ebf32247ebaf2b2628f324b3d77799b6aed
5
5
  SHA512:
6
- metadata.gz: 4f6b3a8f6c65310e782b9fd099da1edd05f70b8b66c9e7b1e690387be6f28f086b4d72a5adf4d641148c3729dbbfd4ec28db41766c0e5837bc54bff112671dcb
7
- data.tar.gz: 776f84d792a78b870ce940302b61dcf264f70e10282747bd1e5e6e9029ffad0d30b66ff289c1ba6b4223174e467b413e22ad91eaa96a13bbaad0b0d3edd4a7e1
6
+ metadata.gz: 7f012c7724dddab12ef370a57d7e5f5d00d6f556cbd5bb4aa5f0b11c33298bcc2eee4a523cce73dbcb1e669c4824d57bd14c8a67780741bb3186b65ed568ac68
7
+ data.tar.gz: d51f55008b3cfd58a48e312af82a9538f00e75f6e857b0601d83c684bbfdd30612f031e89ee809811ccc99614e91af1653f761106cda6f00f1c7d34959bab1c4
@@ -87,7 +87,7 @@ jobs:
87
87
  - uses: actions/setup-ruby@v1
88
88
  - name: Setup
89
89
  run : |
90
- gem install bundler bundler-audit
90
+ gem install bundler:2.2.25 bundler-audit:0.9.0.1
91
91
  bundle install
92
92
  - name: Run Bundler Audit
93
93
  run : bundle audit --update
data/.rubocop.yml CHANGED
@@ -19,3 +19,6 @@ Metrics/MethodLength:
19
19
 
20
20
  Layout/LineLength:
21
21
  Max: 80
22
+
23
+ Naming/MemoizedInstanceVariableName:
24
+ EnforcedStyleForLeadingUnderscores: optional
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
- # Changelog
1
+ ## Changelog
2
2
 
3
- ## 0.1.0 [☰](https://github.com/victorauthiat/company_number)
3
+ ### 0.1.1 - 2022-04-04
4
+ * Features:
5
+ * Add dictionary to return the company number metadata - b19c8d9
4
6
 
5
- - Initial release
7
+ * Deprecations:
8
+ * Remove `regexp` attr_reader (moved to metadata) - #3
9
+ * Remove `countries` attr_reader to use `CompanyNumber::Number#valid_countries` - #3
10
+
11
+ * Bug fixes:
12
+ * Fix `CompanyNumber::Number#to_s` method not to return trailing whitespace when country code is not filled in - 9b4f3c53
13
+
14
+ * Enhancements:
15
+ * Update RuboCop configuration - e34eca5
16
+
17
+ ### 0.1.0 - 2021-09-24
18
+
19
+ * Initial release
data/README.md CHANGED
@@ -27,7 +27,7 @@ You can obtain a `CompanyNumber::Number` object calling `parse` method:
27
27
  ```ruby
28
28
  company_number = CompanyNumber.parse('123456789', :fr)
29
29
 
30
- # => #<CompanyNumber::Number:0x00007fd945013d50 @company_number="123456789", @countries=[:bg, :fr, :gr, :lt, :no, :pt, :si, :ch, :gb], @country_code=:fr, @regexp=/^(\d{9}|\d{14})$/>
30
+ # => #<CompanyNumber::Number:0x00007fc015d04e18 @company_number="123456789", @country_code=:fr, @metadata={:country=>"France", :name=>"Numéro SIREN ou SIRET", :regexp=>"^(\\d{9}|\\d{14})$", :pattern=>"9 numbers (XXXXXXXXX) or 14 numbers (XXXXXXXXXXXXXX)"}>
31
31
  ```
32
32
 
33
33
  Then you can run validation methods
@@ -41,13 +41,20 @@ company_number.valid_for_country?(:at)
41
41
  # => false
42
42
  ```
43
43
 
44
- You can also fetch matched countries
44
+ You can also fetch valid countries
45
45
 
46
46
  ```ruby
47
- company_number.countries
47
+ company_number.valid_countries
48
48
  # => [:bg, :fr, :gr, :lt, :no, :pt, :si, :ch, :gb]
49
49
  ```
50
50
 
51
+ Additionally you can get metadata
52
+
53
+ ```ruby
54
+ company_number.metadata
55
+ # => {:country=>"France", :name=>"Numéro SIREN ou SIRET", :regexp=>"^(\\d{9}|\\d{14})$", :pattern=>"9 numbers (XXXXXXXXX) or 14 numbers (XXXXXXXXXXXXXX)"}
56
+ ```
57
+
51
58
  There is a `to_s` method, which returns the company number with the country code.
52
59
 
53
60
  ```ruby
@@ -59,7 +66,7 @@ There is a `to_h` method, which returns all attr_reader
59
66
 
60
67
  ```ruby
61
68
  company_number.to_h
62
- # => {:company_number=>"123456789", :country_code=>:fr, :countries=>[:bg, :fr, :gr, :lt, :no, :pt, :si, :ch, :gb], :regexp=>/^(\d{9}|\d{14})$/}
69
+ # => {:company_number=>"123456789", :country_code=>:fr, :metadata=>{:country=>"France", :name=>"Numéro SIREN ou SIRET", :regexp=>"^(\\d{9}|\\d{14})$", :pattern=>"9 numbers (XXXXXXXXX) or 14 numbers (XXXXXXXXXXXXXX)"}}
63
70
  ```
64
71
 
65
72
  You can compare 2 instances of `CompanyNumber::Number` with `==` method
@@ -69,6 +76,12 @@ CompanyNumber.parse('123') == CompanyNumber.parse('123')
69
76
  # => true
70
77
  ```
71
78
 
79
+ Finally you can get the whole dictionary
80
+ ```ruby
81
+ CompanyNumber.dictionary
82
+ # => {:at=>{:country=>"Austria", :name=>"Firmenbuchnummer", :regexp=>"^([a-zA-Z]{2}\\d{1,6}|\\d{1,6})[A-Z]$", :pattern=>"2 letters + 6 numbers + 1 letter (LLXXXXXXL)", :variations=>"1-6 numbers + 1 letter (XXXXXXL)"}, ...}
83
+ ```
84
+
72
85
  ## Development
73
86
 
74
87
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,214 @@
1
+ at:
2
+ country: Austria
3
+ name: Firmenbuchnummer
4
+ regexp: ^([a-zA-Z]{2}\d{1,6}|\d{1,6})[A-Z]$
5
+ pattern: 2 letters + 6 numbers + 1 letter (LLXXXXXXL)
6
+ variations: 1-6 numbers + 1 letter (XXXXXXL)
7
+
8
+ be:
9
+ country: Belgium
10
+ name: Numéro d'entreprise Vestigingseenheidsnummer
11
+ regexp: ^\d{10}$
12
+ pattern: 10 numbers (XXXXXXXXXX)
13
+
14
+ bg:
15
+ country: Bulgaria
16
+ name: ЕИК (EIK)/ПИК (PIK) (UIC/PIC)
17
+ regexp: ^(\d{9}|\d{13})$
18
+ pattern: 9 numbers (XXXXXXXXX)
19
+ variations: 13 numbers (XXXXXXXXXXXXX)
20
+
21
+ hr:
22
+ country: Croatia
23
+ name: Matični broj poslovnog subjekta (MBS)
24
+ regexp: ^(\d{8}|\d{11})$
25
+ pattern: 11 numbers (XXXXXXXXXXX)
26
+ variations: 8 numbers (XXXXXXXX)
27
+
28
+ cy:
29
+ country: Cyprus
30
+ regexp: ^[a-zA-Z]{2}\d{6}$
31
+ name: Αριθμός Μητρώου Εταιρίας Şirket kayıt numarası
32
+ pattern: 2 letters + 6 numbers (HEXXXXXX)
33
+
34
+ cz:
35
+ country: Czech Republic
36
+ name: Identifikační číslo
37
+ regexp: ^\d{8}$
38
+ pattern: 8 numbers (XXXXXXXX)
39
+
40
+ dk:
41
+ country: Denmark
42
+ name: CVR-nummer
43
+ regexp: ^\d{8}$
44
+ pattern: 8 numbers (XXXXXXXX)
45
+
46
+ ee:
47
+ country: Estonia
48
+ name: Kood
49
+ regexp: ^\d{8}$
50
+ pattern: 8 numbers (XXXXXXXX)
51
+
52
+ fi:
53
+ country: Finland
54
+ name: Y-tunnus FO-nummer
55
+ regexp: ^\d{8}$
56
+ pattern: 8 numbers (XXXXXXXX)
57
+
58
+ fr:
59
+ country: France
60
+ name: Numéro SIREN ou SIRET
61
+ regexp: ^(\d{9}|\d{14})$
62
+ pattern: 9 numbers (XXXXXXXXX) or 14 numbers (XXXXXXXXXXXXXX)
63
+
64
+ de:
65
+ country: Germany
66
+ name: Nummer der Firma Registernummer
67
+ regexp: ^[a-zA-Z]{1,3}\d{1,6}[a-zA-Z]{0,3}$
68
+ pattern: 2-3 letters + 6 numbers (LLXXXXXX)
69
+ variations: |
70
+ 2-3 letters + 1-6 numbers (LLLXXXX)
71
+ or 2-3 letters + 1-6 numbers + 1 letter (LLLXXXXXXL)
72
+ or 2-3 letters + 1-6 numbers + 1-2 letter (LLLXXXXXXLL)
73
+
74
+ gr:
75
+ country: Greece
76
+ name: Αριθμό Φορολογικού Μητρώου (Α.Φ.Μ.)
77
+ regexp: ^(\d{9}|\d{12})$
78
+ pattern: 12 numbers (XXXXXXXXXXXX)
79
+ variations: 9 numbers (XXXXXXXXX)
80
+
81
+ hu:
82
+ country: Hungary
83
+ name: Cégjegyzékszáma
84
+ regexp: ^[a-zA-Z]{2}\d{10}$
85
+ pattern: 2 letters + 10 numbers (LLXXXXXXXXXX)
86
+
87
+ ie:
88
+ country: Ireland
89
+ name: Company Number
90
+ regexp: ^(\d{5}|\d{6})$
91
+ pattern: 6 numbers (XXXXXX)
92
+ variations: 5 numbers (XXXXX)
93
+
94
+ is:
95
+ country: Island
96
+ name: TIN
97
+ regexp: ^\d{10}$
98
+ pattern: 10 numbers (XXXXXXXXXX)
99
+
100
+ it:
101
+ country: Italy
102
+ name: Codice fiscale
103
+ regexp: ^[a-zA-Z]{2}\d{7}|\d{11}$
104
+ pattern: 11 numbers (XXXXXXXXXXX)
105
+ variations: 2 letters + 7 numbers (LLXXXXXXX)
106
+
107
+ lv:
108
+ country: Latvia
109
+ name: Reģistrācijas numurs
110
+ regexp: ^\d{11}$
111
+ pattern: 11 numbers (XXXXXXXXXXX)
112
+
113
+ li:
114
+ country: Liechtenstein
115
+ name: UID
116
+ regexp: ^[a-zA-Z]{3}\d{3}\s\d{3}\s\d{3}$
117
+ pattern: 3 letters + 9 numbers (LLLXXX XXX XXX)
118
+
119
+ lt:
120
+ country: Lithuania
121
+ name: Juridinio asmens kodas
122
+ regexp: ^\d{9}$
123
+ pattern: 9 numbers (XXXXXXXXX)
124
+
125
+ lu:
126
+ country: Luxembourg
127
+ name: Numéro d'immatriculation
128
+ regexp: ^[a-zA-Z]{1}\d{6}|[a-jA-J]\d{3}$
129
+ pattern: 1 letter + 6 numbers (LXXXXXX)'
130
+ variations: 1 letter (from A to J) + 3 numbers (AXXX)
131
+
132
+ mt:
133
+ country: Malta
134
+ name: Registration Number
135
+ regexp: ^[a-zA-Z]{1}\d{5}$
136
+ pattern: 1 letter + 5 numbers (LXXXXX)
137
+
138
+ nl:
139
+ country: Netherlands
140
+ name: KvK-nummer
141
+ regexp: ^\d{8}$
142
+ pattern: 8 numbers (XXXXXXXX)
143
+
144
+ "no":
145
+ country: Norway
146
+ name: TIN
147
+ regexp: ^(\d{9}|\d{11})$
148
+ pattern: 11 numbers (XXXXXXXXXXX)
149
+ variations: 9 numbers (XXXXXXXXX)
150
+
151
+ pl:
152
+ country: Poland
153
+ name: Numer w Krajowym Rejestrze Sądowym (numer KRS)
154
+ regexp: ^(\d{6}|\d{8})$
155
+ pattern: 8 numbers (XXXXXXXX)
156
+ variations: 6 numbers (XXXXXX)
157
+
158
+ pt:
159
+ country: Portugal
160
+ name: Número de Identificação Pessoa Coletiva (NIPC)
161
+ regexp: ^(\d{9}|\d{3,6})$
162
+ pattern: 9 numbers (XXXXXXXXX)
163
+ variations: 3-6 numbers (XXXXXX)
164
+
165
+ ro:
166
+ country: Romania
167
+ name: Număr de ordine în Registrul Comerţului
168
+ regexp: ^\d{3}\s\d{2}\s\d{3}$
169
+ pattern: 8 numbers (XXX XX XXX)
170
+
171
+ sk:
172
+ country: Slovakia
173
+ name: Identifikačného čísla Identification number
174
+ regexp: ^\d{3}\s\d{2}\s\d{3}$
175
+ pattern: 8 numbers (XXX XX XXX)
176
+
177
+ si:
178
+ country: Slovenia
179
+ name: Matična številka
180
+ regexp: ^\d{10}|\d{7,10}$
181
+ pattern: 10 numbers (XXXXXXXXXX)
182
+ variations: 7 - 10 numbers (XXXXXXXXXX)
183
+
184
+ es:
185
+ country: Spain
186
+ name: Número de identificación fiscal (NIF)
187
+ regexp: ^[a-zA-Z]{1}(\d{8}|\d{7}[a-zA-Z]{1})$
188
+ pattern: 1 letter + 8 numbers (LXXXXXXXX)
189
+ variations: 1 letter + 7 numbers + 1 letter (LXXXXXXXL)
190
+
191
+ se:
192
+ country: Sweden
193
+ name: Registreringsnummer
194
+ regexp: ^\d{10}$
195
+ pattern: 10 numbers (XXXXXXXXXX)
196
+
197
+ ch:
198
+ country: Switzerland
199
+ name: UID
200
+ regexp: ^CHE\d{9}|\d{9}$
201
+ pattern: 9 numbers (XXXXXXXXX)
202
+ variations: CHE + 9 numbers
203
+
204
+ gb:
205
+ country: United Kingdom
206
+ name: Company Number Registration Number
207
+ regexp: ^\d{8}|(OC|SC|NI)\d{6}|R\d{7}|IP\d{5}R$
208
+ pattern: 8 numbers (XXXXXXX)
209
+ variations: |
210
+ OC + 6 numbers (OCXXXXXX)
211
+ or SC + 6 numbers (SCXXXXXX)
212
+ or NI + 6 numbers (NIXXXXXX)
213
+ or R + 7 numbers (RXXXXXXX)
214
+ or IP + 5 numbers + R (IPXXXXXR)
@@ -1,14 +1,30 @@
1
1
  module CompanyNumber
2
2
  class Number
3
- attr_reader :company_number, :country_code, :countries, :regexp
3
+ attr_reader :company_number, :country_code, :metadata
4
4
 
5
5
  def initialize(company_number, country_code = nil)
6
- validate_attributes(company_number, country_code)
6
+ check_param_type(company_number, [String])
7
+ check_param_type(country_code, [NilClass, Symbol, String])
7
8
 
8
9
  @company_number = company_number
9
- @country_code = country_code&.downcase&.to_sym
10
- @countries = fetch_countries
11
- @regexp = CompanyNumber::VALIDATIONS[@country_code]
10
+ @country_code = country_code&.downcase&.to_sym
11
+ @metadata = CompanyNumber.dictionary[@country_code] || {}
12
+ end
13
+
14
+ def to_h
15
+ {
16
+ company_number: @company_number,
17
+ country_code: @country_code,
18
+ metadata: @metadata
19
+ }
20
+ end
21
+
22
+ def to_s
23
+ "#{@company_number} #{@country_code}".strip
24
+ end
25
+
26
+ def ==(other)
27
+ self.class == other.class && other.to_s == to_s
12
28
  end
13
29
 
14
30
  def valid?
@@ -16,48 +32,37 @@ module CompanyNumber
16
32
  end
17
33
 
18
34
  def valid_country?
19
- CompanyNumber::VALIDATIONS.keys.include?(@country_code)
35
+ CompanyNumber.dictionary.keys.include?(@country_code)
20
36
  end
21
37
 
22
38
  def valid_for_country?(country_code)
23
- !!(@company_number =~ CompanyNumber::VALIDATIONS[country_code])
24
- end
39
+ check_param_type(country_code, [Symbol])
25
40
 
26
- def to_s
27
- "#{@company_number} #{@country_code}"
41
+ !!(@company_number =~ country_code_regexp(country_code))
28
42
  end
29
43
 
30
- def to_h
31
- {
32
- company_number: @company_number,
33
- country_code: @country_code,
34
- countries: @countries,
35
- regexp: @regexp
36
- }
37
- end
44
+ def valid_countries
45
+ return [] if !valid_country? && @country_code
38
46
 
39
- def ==(other)
40
- self.class == other.class && other.to_s == to_s
47
+ CompanyNumber
48
+ .dictionary
49
+ .keys
50
+ .select { |country_code| valid_for_country?(country_code) }
41
51
  end
42
52
 
43
53
  private
44
54
 
45
- def validate_attributes(company_number, country_code)
46
- unless company_number.is_a?(String)
47
- raise ArgumentError, 'Expect company_number to be String'
48
- end
49
-
50
- return if [NilClass, Symbol, String].include?(country_code.class)
55
+ def country_code_regexp(country_code)
56
+ regexp = CompanyNumber.dictionary.dig(country_code, :regexp)
51
57
 
52
- raise ArgumentError, 'Expect country_code to be String, Symbol or nil'
58
+ Regexp.new(regexp) unless regexp.nil?
53
59
  end
54
60
 
55
- def fetch_countries
56
- return [] if !valid_country? && @country_code
61
+ def check_param_type(param, expected_classes = [])
62
+ return if expected_classes.include?(param.class)
57
63
 
58
- CompanyNumber::VALIDATIONS.select do |country_code, regexp|
59
- country_code if @company_number =~ regexp
60
- end.keys
64
+ raise ArgumentError,
65
+ "Expect class of #{param} to be #{expected_classes.join(', ')}"
61
66
  end
62
67
  end
63
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CompanyNumber
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,45 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "yaml"
3
4
  require_relative "company_number/version"
4
5
 
5
6
  module CompanyNumber
6
7
  autoload :Number, 'company_number/number'
7
8
 
8
- VALIDATIONS = {
9
- at: /^([a-zA-Z]{2}\d{1,6}|\d{1,6})[A-Z]$/,
10
- be: /^\d{10}$/,
11
- bg: /^(\d{9}|\d{13})$/,
12
- hr: /^(\d{8}|\d{11})$/,
13
- cz: /^\d{8}$/,
14
- dk: /^\d{8}$/,
15
- ee: /^\d{8}$/,
16
- fi: /^\d{8}$/,
17
- fr: /^(\d{9}|\d{14})$/,
18
- de: /^[a-zA-Z]{1,3}\d{1,6}[a-zA-Z]{0,3}$/,
19
- gr: /^(\d{9}|\d{12})$/,
20
- hu: /^[a-zA-Z]{2}\d{10}$/,
21
- ie: /^(\d{5}|\d{6})$/,
22
- is: /^\d{10}$/,
23
- it: /^[a-zA-Z]{2}\d{7}|\d{11}$/,
24
- lv: /^\d{11}$/,
25
- li: /^[a-zA-Z]{3}\d{3}\s\d{3}\s\d{3}$/,
26
- lt: /^\d{9}$/,
27
- lu: /^[a-zA-Z]{1}\d{6}|[a-jA-J]\d{3}$/,
28
- mt: /^[a-zA-Z]{1}\d{5}$/,
29
- nl: /^\d{8}$/,
30
- no: /^(\d{9}|\d{11})$/,
31
- pl: /^(\d{6}|\d{8})$/,
32
- pt: /^(\d{9}|\d{3,6})$/,
33
- ro: /^\d{3}\s\d{2}\s\d{3}$/,
34
- sk: /^\d{3}\s\d{2}\s\d{3}$/,
35
- si: /^\d{10}|\d{7,10}$/,
36
- es: /^[a-zA-Z]{1}(\d{8}|\d{7}[a-zA-Z]{1})$/,
37
- se: /^\d{10}$/,
38
- ch: /^CHE\d{9}|\d{9}$/,
39
- gb: /^\d{8}|(OC|SC|NI)\d{6}|R\d{7}|IP\d{5}R$/
40
- }.freeze
9
+ class << self
10
+ def parse(company_number, country_code = nil)
11
+ CompanyNumber::Number.new(company_number, country_code)
12
+ end
41
13
 
42
- def self.parse(company_number, country_code = nil)
43
- CompanyNumber::Number.new(company_number, country_code)
14
+ def dictionary
15
+ @_dictionary ||= YAML.safe_load(
16
+ File.read(File.join(File.dirname(__FILE__), '../config/dictionary.yml')),
17
+ symbolize_names: true
18
+ )
19
+ end
44
20
  end
45
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: company_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - victorauthiat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - bin/console
101
101
  - bin/setup
102
102
  - company_number.gemspec
103
+ - config/dictionary.yml
103
104
  - lib/company_number.rb
104
105
  - lib/company_number/number.rb
105
106
  - lib/company_number/version.rb
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubygems_version: 3.0.3
126
+ rubygems_version: 3.1.6
126
127
  signing_key:
127
128
  specification_version: 4
128
129
  summary: Validate a company number according to a country code