GoldNumber 1.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
+ SHA1:
3
+ metadata.gz: 7862606436c565d8fb6b58ff8c2ece207400b565
4
+ data.tar.gz: a2fe30beeb6231a96fb1175fb9065402c87dce18
5
+ SHA512:
6
+ metadata.gz: 2d747cb3a19353f09236716669388efa5fb74803de89d545b3ef0d03b3f4d9c8cf7e0ed0aaf84255d89b8cc2526b19dd5013eac43e73679f92f28d63e4ce0998
7
+ data.tar.gz: e3d94d4761d9b921a35e0afa33ad7ba89f9c11dd892829788ccec58ff55a604fefab43d62a5e1d73097351ff7e68ee114e4b3e889b67da9e77fe444fa440800e
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in GoldNumber.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'GoldNumber/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "GoldNumber"
8
+ spec.version = GoldNumber::VERSION
9
+ spec.authors = ["Adrian Bordinc"]
10
+ spec.email = ["adrian.bordinc@gmail.com"]
11
+ spec.summary = %q{Small utility to check for premium phone numbers}
12
+ spec.homepage = "http://github.com/ellimist"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake"
21
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Adrian Bordinc
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # GoldNumber
2
+
3
+ GoldNumber is a small utility that checks if a phone number can be considered Premium
4
+
5
+ ## What is a Gold Number?
6
+
7
+ A gold number is a premium phone number that is more "good looking", and easier to remember.
8
+
9
+ What classifies a number as "good looking" or easy to remember?
10
+
11
+ 1. "71 999999" - Identical numbers
12
+ 2. "71 123 321" - Palindrome => two reversed groups of numbers
13
+ 3. "71 123456" - Consecutive numbers in ascending order
14
+ 4. "71 654321" - Consecutive numbers in descending order
15
+ 5. "71 11 22 33" - Palindrome pairs :)
16
+ 6. "71 123 123" - 2 identical groups
17
+ 7. "71 91 91 91" - Repetitive groups
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'GoldNumber'
24
+
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install GoldNumber
33
+
34
+ ## Usage
35
+
36
+ You can require it in your application
37
+
38
+ require 'goldnumber'
39
+
40
+ GoldNumber::GoldNumber.new(12333333).valid? # => false
41
+ GoldNumber::GoldNumber.new(45454545).valid? # => true
42
+
43
+
44
+ In different countries, phone numbers have a different length/format and sometimes the phone carriers have a prefix.
45
+ You can pass a second parameter in the initialization of the GoldNumber and the specified number of characters from the beginning of the number will be ignored.
46
+
47
+ require 'goldnumber'
48
+
49
+ GoldNumber::GoldNumber.new(12333333).valid? # => false
50
+ GoldNumber::GoldNumber.new(12333333, 2).valid? # => true
51
+
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/ellimist/GoldNumber/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module GoldNumber
2
+ VERSION = "1.0"
3
+ end
data/lib/GoldNumber.rb ADDED
@@ -0,0 +1,128 @@
1
+ require "GoldNumber/version"
2
+
3
+ module GoldNumber
4
+ class GoldNumber
5
+
6
+ def initialize(number, ignored_prefix=nil)
7
+
8
+ # Receives both Integers and Strings as parameters
9
+ if (number.is_a? Integer) || (number.is_a? String)
10
+ number = (number.is_a? Integer) ? number.to_s : number
11
+ @number = (ignored_prefix.nil?) ? number : number[ignored_prefix..-1]
12
+ else
13
+ raise "Wrong parameter type: number is expected to be Integer or String"
14
+ end
15
+ end
16
+
17
+ # Checks if a number can be classified as a Gold Number
18
+ # @return [Boolean]
19
+ def valid?
20
+ if (identical? ||
21
+ palindrome? ||
22
+ consecutive_ascending? ||
23
+ consecutive_descending? ||
24
+ two_identical_groups? ||
25
+ palindrome_pairs? ||
26
+ repetitive_pairs? ||
27
+ l33t?)
28
+
29
+ true
30
+ else
31
+ false
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ # Checks if a number has all characters identical
38
+ # Ex: 77777777
39
+ def identical?
40
+ valid = true;
41
+ @number.split("").each_with_index do |char, i|
42
+ if valid && (i < @number.length-1)
43
+ valid = (char == @number[i+1])
44
+ end
45
+ end
46
+ valid
47
+ end
48
+
49
+ # Checks if a number is palindrome
50
+ # Ex: 5020 0205
51
+ #TODO: Second thoughts, maybe this isn't a Gold Number as it looks a bit ugly. Get the requirements straight :)
52
+ def palindrome?
53
+ @number == @number.reverse
54
+ end
55
+
56
+ # Checks if the number has consecutive ascending numbers
57
+ # Ex: 12345678
58
+ def consecutive_ascending?
59
+ valid = true
60
+ @number.chars.each_with_index do |char, i|
61
+ if valid && (i < @number.length-1)
62
+ valid = (char.to_i+1 == @number[i+1].to_i)
63
+ end
64
+ end
65
+ valid
66
+ end
67
+
68
+ # Checks if a number has consecutive descending numbers
69
+ # Ex: 87654321
70
+ def consecutive_descending?
71
+ valid = true
72
+ @number.chars.each_with_index do |char, i|
73
+ if valid && (i < @number.length-1)
74
+ valid = (char.to_i-1 == @number[i+1].to_i)
75
+ end
76
+ end
77
+ valid
78
+ end
79
+
80
+ # Checks if a number is made out of 2 identical groups of numbers
81
+ # Only valid for even numbers of characters in a number
82
+ # Ex: 12341234
83
+ def two_identical_groups? # I'll run out of method name soon. I guarantee it.
84
+ return false if @number.length % 2 == 1
85
+ valid = (@number[0...@number.length/2] == @number[@number.length/2..-1])
86
+ end
87
+
88
+ # Checks if a number can be splitted into groups of 2, each group being a palindrome
89
+ # Only valid for even numbers of characters in a number
90
+ # Ex: 91112233 or 88554477
91
+ def palindrome_pairs?
92
+ return false if @number.length % 2 == 1
93
+
94
+ groups, valid = [], true
95
+
96
+ groups = @number.chars.each_slice(2).map(&:join)
97
+ groups.each do |pair|
98
+ if valid
99
+ valid = (pair == pair.reverse)
100
+ end
101
+ end
102
+ valid
103
+ end
104
+
105
+ # Checks if a number can be splitted into groups of 2, all groups being identical
106
+ # Only valid for even numbers of characters in a number
107
+ # Ex: 91919191 or 80565656
108
+ def repetitive_pairs?
109
+ return false if @number.length % 2 == 1
110
+
111
+ groups, valid = [], true
112
+
113
+ groups = @number.chars.each_slice(2).map(&:join)
114
+ groups.each_with_index do |pair, i|
115
+ if valid && (i < groups.length-1)
116
+ valid = (pair == groups[i+1])
117
+ end
118
+ end
119
+ valid
120
+ end
121
+
122
+ # Checks if you have a 1337 number
123
+ # Ex: 13371337
124
+ def l33t?
125
+ return true if @number.include? "1337"
126
+ end
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: GoldNumber
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Bordinc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-11 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - adrian.bordinc@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - GoldNumber.gemspec
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/GoldNumber.rb
55
+ - lib/GoldNumber/version.rb
56
+ homepage: http://github.com/ellimist
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Small utility to check for premium phone numbers
80
+ test_files: []