countries_data 1.0.0
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 +7 -0
- data/lib/countries_data/collection.rb +35 -0
- data/lib/countries_data/country.rb +32 -0
- data/lib/countries_data/data.yml +1993 -0
- data/lib/countries_data/phone_validator.rb +54 -0
- data/lib/countries_data/version.rb +3 -0
- data/lib/countries_data.rb +6 -0
- metadata +52 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative './collection'
|
2
|
+
|
3
|
+
module CountriesData
|
4
|
+
class PhoneValidator
|
5
|
+
attr_reader :code
|
6
|
+
attr_reader :number
|
7
|
+
|
8
|
+
def initialize(code: nil, number: nil)
|
9
|
+
@code = code
|
10
|
+
@number = number
|
11
|
+
end
|
12
|
+
|
13
|
+
PHONE_REGEXP = Regexp.new('^\\d+$')
|
14
|
+
|
15
|
+
def valid?
|
16
|
+
valid_format? && valid_code? && valid_length?
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_format?
|
20
|
+
PHONE_REGEXP.match?(code) && PHONE_REGEXP.match?(number)
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid_code?
|
24
|
+
!countries.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid_length?
|
28
|
+
return false unless number&.length
|
29
|
+
|
30
|
+
length = number.length
|
31
|
+
length >= min_length && length <= max_length
|
32
|
+
end
|
33
|
+
|
34
|
+
def min_length
|
35
|
+
countries
|
36
|
+
.map(&:phone_min_length)
|
37
|
+
.compact
|
38
|
+
.min || 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def max_length
|
42
|
+
countries
|
43
|
+
.map(&:phone_max_length)
|
44
|
+
.compact
|
45
|
+
.max || Float::INFINITY
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def countries
|
51
|
+
@countries = Collection.find_by_phone_code(code)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: countries_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manuel de la Torre
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/countries_data.rb
|
20
|
+
- lib/countries_data/collection.rb
|
21
|
+
- lib/countries_data/country.rb
|
22
|
+
- lib/countries_data/data.yml
|
23
|
+
- lib/countries_data/phone_validator.rb
|
24
|
+
- lib/countries_data/version.rb
|
25
|
+
homepage: https://github.com/zenfi/countries-data
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata:
|
29
|
+
rubygems_mfa_required: 'true'
|
30
|
+
homepage_uri: https://github.com/zenfi/countries-data
|
31
|
+
source_code_uri: https://github.com/zenfi/countries-data
|
32
|
+
changelog_uri: https://github.com/zenfi/countries-data/CHANGELOG.md
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.6'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubygems_version: 3.0.3.1
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Contains useful information about all of the countries
|
52
|
+
test_files: []
|