msisdn-ph 0.0.1

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
+ SHA1:
3
+ metadata.gz: 2b06d312a53ac221bea5b756e7f574c876a13c55
4
+ data.tar.gz: abd670e38778c29748c3ffa0a6b8296cf4919cf2
5
+ SHA512:
6
+ metadata.gz: fb55b0ebab7cef41f396b01d78bbee9aab041d301289374ff621532c28cacbba22cfbf3b6b3dbb4e17b7e58370afb82b6ae388ba8fe0bdef8dc024a44c5ba4bf
7
+ data.tar.gz: 52eea5b1a1924b8f215f853cc6059ceedc831d7f68be344f602c661e29b86b4bd413c980d6fdaf3ad09578cbed3711634a5911a01f52cbb902feb548ab47a76c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Msisdn.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jameson Candava
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/Msisdn.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'Msisdn/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "msisdn-ph"
8
+ spec.version = Msisdn::VERSION
9
+ spec.authors = ["Jameson Candava"]
10
+ spec.email = ["candavajameson@gmail.com"]
11
+
12
+ spec.summary = %q{MSISDN Philippine identification.}
13
+ spec.description = %q{An MSISDN identification and cleaner library for Philippine telco subscribers.}
14
+ spec.homepage = "http://github.com/coreproc/msisdn-ph-gem"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "3.2.0"
26
+ end
data/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # MsisdnPH - Ruby
2
+
3
+ Easily validate and manipulate Philippine mobile numbers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'Msisdn'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install Msisdn
20
+
21
+ ## Usage
22
+
23
+ ### Validate the mobile number
24
+
25
+ ```ruby
26
+ mobileNumber = '09171231234'
27
+
28
+ if MsisdnPH::Msisdn.validate(mobileNumber)
29
+ puts 'Valid mobile number'
30
+ else
31
+ puts 'Invalid mobile number'
32
+ end
33
+ ```
34
+
35
+ The `validate` method cleans the given mobile number and validates it so even if the mobile number is malformed or has other characters within it, it will still return true as long as the number is really valid:
36
+
37
+ ```ruby
38
+ validMobileNumber = '+639171231234'
39
+ validMobileNumber = '+63-917-123-1234'
40
+ validMobileNumber = '0917-123-1234'
41
+ validMobileNumber = '0917.123.1234'
42
+ validMobileNumber = '63 917 123 12 34 '
43
+ ```
44
+
45
+ ### Instantiate an MSISDN object
46
+
47
+ You can instantiate an MSISDN object and get a standardized format of your mobile number and even get the telco attached to the mobile number using this object.
48
+
49
+ ```ruby
50
+ mobileNumber = '09171231234'
51
+
52
+ msisdn = MsisdnPH::Msisdn.new(mobileNumber)
53
+ ```
54
+
55
+ The MSISDN object will throw an `Exception` if you give it an invalid mobile number, so it's best to either catch the exception OR validate it before creating an MSISDN object.
56
+
57
+ ```ruby
58
+ invalidMobileNumber = '0917-123-123'
59
+
60
+ begin
61
+ msisdn = MsisdnPH::Msisdn.new(invalidMobileNumber)
62
+ rescue StandardError
63
+ puts 'The number is invalid'
64
+ end
65
+ ```
66
+
67
+ OR
68
+
69
+ ```ruby
70
+ invalidMobileNumber = '0917-123-123'
71
+
72
+ if MsisdnPH::Msisdn.validate(invalidMobileNumber)
73
+ msisdn = MsisdnPH::Msisdn.new(invalidMobileNumber)
74
+ else
75
+ puts 'Invalid mobile number'
76
+ end
77
+ ```
78
+
79
+ ### Return a standardized format of your mobile number
80
+
81
+ When you've instantiated an `Msisdn` object, you can return the mobile number in any format you want.
82
+
83
+ ```ruby
84
+ mobileNumber = '09171231234'
85
+
86
+ msisdn = MsisdnPH::Msisdn.new(mobileNumber)
87
+
88
+ puts msisdn.get() // will return 09171231234
89
+
90
+ puts msisdn.get(true) // will return +639171231234
91
+
92
+ puts msisdn.get(false, '-') // will return 0917-123-1234
93
+
94
+ puts msisdn.get(true, '-') // will return +63-917-123-1234
95
+
96
+ puts msisdn.get(true, '.') // will return +63.917.123.1234
97
+ ```
98
+
99
+ ### Get the telco operator of a mobile number
100
+
101
+ You can also get the telco operator of the given mobile number - this is based on the included prefixes we have gathered from the telcos.
102
+
103
+ We cannot guarantee that this list is updated so use with a grain of salt.
104
+
105
+ If you want to add to the prefixes, you can find the list inside the `lib/data` directory.
106
+
107
+ ```ruby
108
+ mobileNumber = '09171231234'
109
+
110
+ msisdn = MsisdnPH::Msisdn.new(mobileNumber)
111
+
112
+ puts msisdn.operator // will return Globe
113
+ ```
114
+
115
+ ### Get the prefix of a mobile number
116
+
117
+ You might just want to get the prefix of a mobile number.
118
+
119
+ ```ruby
120
+ mobileNumber = '09171231234'
121
+
122
+ msisdn = MsisdnPH::Msisdn.new(mobileNumber)
123
+
124
+ puts msisdn.prefix // will return 917
125
+ ```
126
+
127
+ ## Development
128
+
129
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
130
+
131
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
132
+
133
+ ## Contributing
134
+
135
+ 1. Fork it
136
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
137
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
138
+ 4. Push to the branch (`git push origin my-new-feature`)
139
+ 5. Create new Pull Request
140
+
141
+
142
+ ## License
143
+
144
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
145
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ Rspec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Msisdn"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/Msisdn.rb ADDED
@@ -0,0 +1,105 @@
1
+ require "Msisdn/version"
2
+ require 'yaml'
3
+
4
+ module MsisdnPH
5
+
6
+ class Msisdn
7
+
8
+ def initialize(msisdn)
9
+ if Msisdn.validate(msisdn) == false
10
+ raise "The supplied MSISDN is not valid
11
+ You can use the `Msisdn.validate()` method to validate
12
+ the MSISDN being passed."
13
+ end
14
+
15
+ @msisdn = Msisdn.clean(msisdn)
16
+
17
+ end
18
+
19
+
20
+ def get(countryCode = false, separator = '')
21
+
22
+ if countryCode == false
23
+ formattedNumber = '0' + @msisdn
24
+
25
+ unless separator.empty?
26
+ formattedNumber.insert(4, separator)
27
+ formattedNumber.insert(8, separator)
28
+ end
29
+
30
+ else
31
+ formattedNumber = '+63' + @msisdn
32
+
33
+ unless separator.empty?
34
+ formattedNumber.insert(3, separator)
35
+ formattedNumber.insert(7, separator)
36
+ formattedNumber.insert(11, separator)
37
+ end
38
+ end
39
+
40
+ return formattedNumber
41
+
42
+ end
43
+
44
+ def prefix
45
+ if @prefix.nil?
46
+ @prefix = @msisdn[0..2]
47
+ end
48
+
49
+ return @prefix
50
+ end
51
+
52
+ def operator
53
+ set_prefix
54
+
55
+ if @globePrefixes.values[0].include?(prefix)
56
+ @operator = "GLOBE"
57
+ elsif @sunPrefixes.values[0].include?(prefix)
58
+ @operator = "SUN"
59
+ elsif @smartPrefixes.values[0].include?(prefix)
60
+ @operator = "SMART"
61
+ else
62
+ @operator = "UNKNOWN"
63
+ end
64
+
65
+ end
66
+
67
+
68
+ def self.validate(mobile_number)
69
+
70
+ mobile_number = self.clean(mobile_number)
71
+
72
+ return !mobile_number.empty? &&
73
+ mobile_number.length === 10
74
+ end
75
+
76
+ def self.clean(msisdn)
77
+
78
+ msisdn = msisdn.gsub(/[^0-9]/, "")
79
+
80
+ if msisdn[0..0] == '0'
81
+ msisdn = msisdn[1..msisdn.length]
82
+ elsif msisdn[0..1] == '63'
83
+ msisdn = msisdn[2..msisdn.length]
84
+ end
85
+
86
+ end
87
+
88
+ private
89
+ def set_prefix
90
+
91
+ if @globePrefixes.nil?
92
+ @globePrefixes = YAML.load_file(File.join(File.dirname(__FILE__), "Msisdn", "data", "globe.yml"))
93
+ end
94
+
95
+ if @smartPrefixes.nil?
96
+ @smartPrefixes = YAML.load_file(File.join(File.dirname(__FILE__), "Msisdn", "data", "smart.yml"))
97
+ end
98
+
99
+ if @sunPrefixes.nil?
100
+ @sunPrefixes = YAML.load_file(File.join(File.dirname(__FILE__), "Msisdn", "data", "sun.yml"))
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,16 @@
1
+ prefix:
2
+ - "817"
3
+ - "905"
4
+ - "906"
5
+ - "915"
6
+ - "916"
7
+ - "917"
8
+ - "925"
9
+ - "926"
10
+ - "927"
11
+ - "935"
12
+ - "936"
13
+ - "937"
14
+ - "994"
15
+ - "996"
16
+ - "997"
@@ -0,0 +1,27 @@
1
+ prefix:
2
+ - "111"
3
+ - "812"
4
+ - "813"
5
+ - "907"
6
+ - "908"
7
+ - "909"
8
+ - "910"
9
+ - "912"
10
+ - "918"
11
+ - "919"
12
+ - "920"
13
+ - "921"
14
+ - "928"
15
+ - "929"
16
+ - "930"
17
+ - "938"
18
+ - "939"
19
+ - "945"
20
+ - "946"
21
+ - "947"
22
+ - "948"
23
+ - "949"
24
+ - "980"
25
+ - "989"
26
+ - "998"
27
+ - "999"
@@ -0,0 +1,8 @@
1
+ prefix:
2
+ - "922"
3
+ - "923"
4
+ - "932"
5
+ - "933"
6
+ - "934"
7
+ - "942"
8
+ - "943"
@@ -0,0 +1,3 @@
1
+ module Msisdn
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: msisdn-ph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jameson Candava
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-27 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: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: An MSISDN identification and cleaner library for Philippine telco subscribers.
56
+ email:
57
+ - candavajameson@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - Msisdn.gemspec
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/Msisdn.rb
72
+ - lib/Msisdn/data/globe.yml
73
+ - lib/Msisdn/data/smart.yml
74
+ - lib/Msisdn/data/sun.yml
75
+ - lib/Msisdn/version.rb
76
+ homepage: http://github.com/coreproc/msisdn-ph-gem
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: MSISDN Philippine identification.
100
+ test_files: []