phone_number_checker 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dfb010b6c67efeef810d8c43ea0d3559cae77bc23304f3fd7f6e2f5b12071cd2
4
+ data.tar.gz: ab689656728a059caaaab26fc497b953193d42aa237556a28df97527f95ea9d3
5
+ SHA512:
6
+ metadata.gz: ec8ee6861064f190278ecccebb81fca7812842467aac0edb7dd8b14e7c0bddf66bdc91ac91d6f499b190218d08d63fe05d02f25c7c948936df892b7e95308c42
7
+ data.tar.gz: 678c2806e6bf867a42fe8c55ca7dde5446652d9a79e3baa8c7b8cb494a397af9301098487bfba53b4ff7cf72b0d69e578374f7c1ea0d27b2dbc8f561e2513553
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2021-08-28
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in phone_number_checker.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Rakib
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # PhoneNumberChecker
2
+
3
+ Phone Number Checker is a Ruby gem. It's used to check valid phone number and also return a valid phone number from a string.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'phone_number_checker'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install phone_number_checker
20
+
21
+ ## Usage
22
+
23
+ Validate Bangladeshi Phone Number from a string:
24
+ ```ruby
25
+ ------------Input------------ ----------Output----------
26
+ '01912345678'.bd_phone? | true
27
+ '+8801912345678'.bd_phone? | true
28
+ '+8800912345678'.bd_phone? | false
29
+ '+880191234567812'.bd_phone? | false
30
+ ```
31
+
32
+ Fetch Bangladeshi Phone Number from a string. It returns **nil** unless valid number:
33
+ ```ruby
34
+ ------------Input------------ ----------Output----------
35
+ '01912345678'.bd_phone | '01912345678'
36
+ '+8801912345678'.bd_phone | '01912345678'
37
+ '+8800912345678'.bd_phone | nil
38
+ '+880191234567812'.bd_phone | nil
39
+ ```
40
+
41
+ Fetch Bangladeshi Phone Number with country code from a string. It returns **nil** unless valid number:
42
+ ```ruby
43
+ ---------------------Input--------------------- ----------Output----------
44
+ '01912345678'.bd_phone_with_country_code | '+8801912345678'
45
+ '+8801912345678'.bd_phone_with_country_code | '+8801912345678'
46
+ '+8800912345678'.bd_phone_with_country_code | nil
47
+ '+880191234567812'.bd_phone_with_country_code | nil
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+
53
+ Bug reports and pull requests are welcome. You can also add other country's phone number validations.
54
+
55
+ **1. Fork it**
56
+
57
+ **2. Create your feature branch [git checkout -b feature_branch].**
58
+
59
+ **3. Commit your changes [git commit -m 'commit message'].**
60
+
61
+ **4. Push to the branch [git push origin feature_branch].**
62
+
63
+ **5. Create new Pull Request.**
64
+
65
+ **Reminder: Need to provide proper test code.**
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "phone_number_checker"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhoneNumberChecker
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "phone_number_checker/version"
4
+
5
+ # PhoneNumberChecker
6
+ module PhoneNumberChecker
7
+ class Error < StandardError; end
8
+
9
+ def bd_phone_regex
10
+ /(^(\+88|0088)?(01)[3456789](\d){8})$/
11
+ end
12
+
13
+ def white_space?
14
+ !!match(/\s/)
15
+ end
16
+
17
+ def bd_phone?
18
+ !!match(bd_phone_regex)
19
+ end
20
+
21
+ def bd_phone
22
+ phone = nil
23
+ length = self.length
24
+ if length == 11 && bd_phone?
25
+ phone = self
26
+ elsif length == 14 && bd_phone?
27
+ phone = slice(3, length)
28
+ elsif length == 15 && bd_phone?
29
+ phone = slice(4, length)
30
+ end
31
+ phone
32
+ end
33
+
34
+ def bd_phone_with_country_code
35
+ phone = nil
36
+ length = self.length
37
+ if length == 11 && bd_phone?
38
+ phone = "+88#{self}"
39
+ elsif length == 14 && bd_phone?
40
+ phone = "+88#{slice(3, length)}"
41
+ elsif length == 15 && bd_phone?
42
+ phone = "+88#{slice(4, length)}"
43
+ end
44
+ phone
45
+ end
46
+ end
47
+
48
+ class String
49
+ include PhoneNumberChecker
50
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phone_number_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Salahuddin Rakib
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ description: Check valid phone number and fetch valid phone number.
56
+ email:
57
+ - salahuddin.rakib.uiu@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/phone_number_checker.rb
72
+ - lib/phone_number_checker/version.rb
73
+ homepage:
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.7.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.1.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Phone Number Check and Fetch.
96
+ test_files: []