cellularity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d731a2d606d316775e5b4ac0b971b18b868a27c7
4
+ data.tar.gz: e5565af4521c6d2d1d905861e17f63b5f46cc61d
5
+ SHA512:
6
+ metadata.gz: fb774e7974672d3758781a88eea07af1095394c27c0044fe7b6c0fcab7dc4d4e02d36898b1ddbdcc46a8bc22a2cee38148604dea7a6e958079585c0630c9fa8d
7
+ data.tar.gz: 8a1c2c29419de4a0b143571d5c8da7a41a56c5529e222ffc560711775e08cdcdf2b17087def966c19834d3406d1247f2214f32f6924b0e390c4d31b51822d147
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cellularity.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 johnotander
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,42 @@
1
+ # Cellularity
2
+
3
+ Determine whether a value is an ICCID, IMEI, or ESN.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cellularity'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cellularity
20
+
21
+ ## Usage
22
+
23
+ #### Currently, Cellularity can handle ESNs, ICCIDs, and IMEIs.
24
+
25
+ ```ruby
26
+ imei = 123456789012345 # It can be a string or a number
27
+ esn = '0xabc12345' # The ESN class can also handle hex.
28
+ iccid = 12345678901234567890
29
+
30
+ ## Validate your values:
31
+ Cellularity::Esn.new(esn).valid? # => true
32
+ Cellularity::Esn.new(imei).valid? # => false
33
+ Cellularity::Iccid.new(iccid).valid? # => true
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cellularity/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cellularity"
8
+ spec.version = Cellularity::VERSION
9
+ spec.authors = ["johnotander"]
10
+ spec.email = ["johnotander@gmail.com"]
11
+ spec.description = %q{Determine whether a string is an ICCID, IMEI, ESN, or MDN.}
12
+ spec.summary = %q{Determine whether a string is an ICCID, IMEI, ESN, or MDN.}
13
+ spec.homepage = "https://www.github.com/johnotander/cellularity"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,9 @@
1
+ require "cellularity/version"
2
+
3
+ require 'cellularity/esn'
4
+ require 'cellularity/imei'
5
+ require 'cellularity/iccid'
6
+
7
+ module Cellularity
8
+
9
+ end
@@ -0,0 +1,31 @@
1
+ module Cellularity
2
+ class Esn
3
+
4
+ attr_accessor :esn
5
+
6
+ def initialize(esn = '')
7
+ self.esn = esn.to_s
8
+ end
9
+
10
+ def valid?
11
+ return is_valid_decimal? if self.esn.length == 11
12
+ return is_valid_hexadecimal_with_prefix? if self.esn.length == 10
13
+ return is_valid_hexadecimal_without_prefix? if self.esn.length == 8
14
+ false
15
+ end
16
+
17
+ def is_valid_decimal?
18
+ !!Integer(self.esn)
19
+ rescue ArgumentError, TypeError
20
+ false
21
+ end
22
+
23
+ def is_valid_hexadecimal_with_prefix?
24
+ self.esn =~ /0x[\h]+/i
25
+ end
26
+
27
+ def is_valid_hexadecimal_without_prefix?
28
+ self.esn =~ /\h+/i && !self.esn.include?('0x')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module Cellularity
2
+ class Iccid
3
+ attr_accessor :iccid
4
+
5
+ def initialize(iccid = '')
6
+ self.iccid = iccid.to_s
7
+ end
8
+
9
+ def valid?
10
+ [19, 20].include?(self.iccid.length) && !!Integer(self.iccid)
11
+ rescue ArgumentError, TypeError
12
+ false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Cellularity
2
+ class Imei
3
+
4
+ attr_accessor :imei
5
+
6
+ def initialize(imei = '')
7
+ self.imei = imei.to_s.gsub(/[^0-9]/, '') # Sometimes formatted as AA-BBBBBB-CCCCCC-D
8
+ end
9
+
10
+ def valid?
11
+ [15, 16].include?(self.imei.length) && !!Integer(self.imei)
12
+ rescue ArgumentError, TypeError
13
+ false
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Cellularity
2
+ VERSION = "0.0.1"
3
+ end
data/spec/esn_spec.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cellularity::Esn do
4
+
5
+ let(:invalid_esn) { ['blah', 12345, :abcdfeghj, '0x123456'] }
6
+ let(:valid_esn) { [12345678909, '0xabc12345', 'abc12345'] }
7
+
8
+ it 'should think that valid esns are, in fact, valid' do
9
+ valid_esn.each { |esn| Cellularity::Esn.new(esn).valid?.should be_true }
10
+ end
11
+
12
+ it 'should think that invalid esns are invalid' do
13
+ invalid_esn.each { |esn| Cellularity::Esn.new(esn).valid?.should be_false }
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cellularity::Iccid do
4
+
5
+ let(:invalid_iccid) { [97824234, 'ahsndjfksnajwkehdms5'] }
6
+ let(:valid_iccid) { [12345678901234567890, '1234567890123456789'] }
7
+
8
+ it 'should think that valid iccids are valid' do
9
+ valid_iccid.each { |iccid| Cellularity::Iccid.new(iccid).valid?.should be_true }
10
+ end
11
+
12
+ it 'should think that invalid iccids are invalid' do
13
+ invalid_iccid.each { |iccid| Cellularity::Iccid.new(iccid).valid?.should be_false }
14
+ end
15
+ end
data/spec/imei_spec.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cellularity::Imei do
4
+
5
+ let(:invalid_imei) { [:blah, '123-123-123-123-12'] }
6
+ let(:valid_imei) { ['123456789012345', 1234567890123456, '12-123456-123456-1'] }
7
+
8
+ it 'should think that valid imeis are valid' do
9
+ valid_imei.each { |imei| Cellularity::Imei.new(imei).valid?.should be_true }
10
+ end
11
+
12
+ it 'should think that invalid imeis are invalid' do
13
+ invalid_imei.each { |imei| Cellularity::Imei.new(imei).valid?.should be_false }
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'cellularity'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cellularity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - johnotander
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Determine whether a string is an ICCID, IMEI, ESN, or MDN.
56
+ email:
57
+ - johnotander@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - cellularity.gemspec
68
+ - lib/cellularity.rb
69
+ - lib/cellularity/esn.rb
70
+ - lib/cellularity/iccid.rb
71
+ - lib/cellularity/imei.rb
72
+ - lib/cellularity/version.rb
73
+ - spec/esn_spec.rb
74
+ - spec/iccid_spec.rb
75
+ - spec/imei_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://www.github.com/johnotander/cellularity
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Determine whether a string is an ICCID, IMEI, ESN, or MDN.
101
+ test_files:
102
+ - spec/esn_spec.rb
103
+ - spec/iccid_spec.rb
104
+ - spec/imei_spec.rb
105
+ - spec/spec_helper.rb