ao_phone_number 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ao_phone_number.rb +39 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3cfa1c7b97c5f23a11ed98de122395b98d3236e1bffdd884c36e479e8e0698e8
4
+ data.tar.gz: e29cc9165fcb65e82a57c08c5d62a5c4347f9b0a5e23ed85afb03540e8aadb86
5
+ SHA512:
6
+ metadata.gz: 22b56bce674be08dceb7238b2d3d0057c64a8cfe590850c9b14b9c356357dae997a510e703ce1a4d86599f0650e2085ff72d666320bc93df9436a80f2971f2c9
7
+ data.tar.gz: 990f6bcfe9e8923635a433f4eb6b5c06074bdf9f232c4a4d605709f6128c384562b825132b75d292c935491344eead25aee2787ccf5575da48103aee8cf141cb
@@ -0,0 +1,39 @@
1
+ class AoPhoneNumber
2
+ # TODO: Phone number codes can have only 2 digits without the third digit being 0.
3
+ UNITEL_CODES = %w[921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948]
4
+ MOVICEL_CODES = %w[911 912 913 914 915 916 917 918 919 991 992 993 994 995 996 997 998]
5
+
6
+ attr_accessor :phone_number
7
+
8
+ def initialize(phone_number)
9
+ @phone_number = phone_number
10
+ end
11
+
12
+ def valid?
13
+ formatted? && operator_code?
14
+ end
15
+
16
+ def unitel?
17
+ formatted? && UNITEL_CODES.include?(operator_code)
18
+ end
19
+
20
+ def movicel?
21
+ formatted? && MOVICEL_CODES.include?(operator_code)
22
+ end
23
+
24
+ private
25
+
26
+ def formatted?
27
+ !/\A[0-9]{9}\z/.match(@phone_number).nil?
28
+ end
29
+
30
+ def operator_code
31
+ return @phone_number[0..2] if formatted?
32
+ raise AoPhoneNumberInvalidError unless formatted?
33
+ end
34
+
35
+ def operator_code?
36
+ all = UNITEL_CODES + MOVICEL_CODES
37
+ all.include?(operator_code)
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ao_phone_number
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Amarildo Lucas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ao_phone_number é uma Ruby gem para validar números e operadoras móveis
14
+ de Angola.
15
+ email: hi@amarildolucas.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/ao_phone_number.rb
21
+ homepage: http://rubygemgem.org/gems/ao_phone_number
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.7.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: ao_phone_number Ruby gem
44
+ test_files: []