iz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +76 -0
- data/Rakefile +11 -0
- data/iz.gemspec +24 -0
- data/lib/iz.rb +24 -0
- data/lib/iz/binary.rb +19 -0
- data/lib/iz/credit_card.rb +19 -0
- data/lib/iz/hexadecimal.rb +19 -0
- data/lib/iz/mac.rb +19 -0
- data/lib/iz/version.rb +3 -0
- data/test/test_binary.rb +25 -0
- data/test/test_credit_card.rb +25 -0
- data/test/test_hexadecimal.rb +25 -0
- data/test/test_mac.rb +26 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69f9f599a28127cc5153125b7a301b36d7f84ee1
|
4
|
+
data.tar.gz: adae005f1fb5f8dab47c2dd2622287f3bdb92354
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8c73b0004ea2510d88e468d05f12a04d0264fc15d2acf694bde6e0ce96456249ca54f5125d8d025a56d3f9d944c4425ac49724dee3bce84ce3a14cac1994b15
|
7
|
+
data.tar.gz: 09de25c0e248fb7c9ff9d7206af6c8994cbfc46da0cd52d3dc8406cb4816e08da45f66936a6dc210b454e62c6462f896c0cddcaec7cf1fa128a494bda040383b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 John Otander
|
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,76 @@
|
|
1
|
+
# iz [![Build Status](https://travis-ci.org/johnotander/iz.svg?master)](https://travis-ci.org/johnotander/iz)
|
2
|
+
|
3
|
+
All your type checking in one place. This intended to serve as simple sanity checking for
|
4
|
+
common formats: IP addresses, zip codes, credit cards, phone numbers, etc. This isn't
|
5
|
+
intended to be the authoritative source on what each of these types are. It seeks to determine
|
6
|
+
whether `'foobar'`, `'(555) 123 - 4567'`, and `nil` are phone numbers, or if `wefwef` looks
|
7
|
+
like an email.
|
8
|
+
|
9
|
+
Compatible with Ruby 1.8 - 2.2.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'iz'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install iz
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Iz.credit_card?('123') # => false
|
31
|
+
Iz.credit_card?('4242424242424242') # => true
|
32
|
+
|
33
|
+
Iz.mac?('ababababab') # => true
|
34
|
+
Iz.mac?(-1) # => false
|
35
|
+
|
36
|
+
Iz.binary?('010101') # => true
|
37
|
+
Iz.binary?('foo') # => false
|
38
|
+
|
39
|
+
Iz.hexadecimal?(0x34) # => true
|
40
|
+
Iz.hexadecimal?('abcdef123') # => true
|
41
|
+
```
|
42
|
+
|
43
|
+
## Upcoming support
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Iz.phone_number?('1234567') # => true
|
47
|
+
|
48
|
+
Iz.zip_code?('12345', :us) # => true
|
49
|
+
|
50
|
+
Iz.ip?(nil) # => false
|
51
|
+
|
52
|
+
Iz.ipv4?('192.168.0.1') # => true
|
53
|
+
|
54
|
+
Iz.ipv6?(:foo) # => false
|
55
|
+
|
56
|
+
Iz.hex_color?('#fff') # => true
|
57
|
+
|
58
|
+
Iz.rgb_color?('rgb(123, 123, 123)') # => true
|
59
|
+
|
60
|
+
Iz.hsl_color?('foobar') # => false
|
61
|
+
|
62
|
+
Iz.url?('google.com') # => true
|
63
|
+
Iz.url?('http://google.com') # => true
|
64
|
+
```
|
65
|
+
|
66
|
+
## Acknowledgements
|
67
|
+
|
68
|
+
Inspired by [is.js](https://github.com/arasatasaygin/is.js).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it ( https://github.com/johnotander/iz/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/iz.gemspec
ADDED
@@ -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 'iz/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'iz'
|
8
|
+
spec.version = Iz::VERSION
|
9
|
+
spec.authors = ['John Otander']
|
10
|
+
spec.email = ['johnotander@gmail.com']
|
11
|
+
spec.summary = %q{All your type checking in one place.}
|
12
|
+
spec.description = %q{Iz provides an API for type checking objects.}
|
13
|
+
spec.homepage = 'https://github.com/johnotander/iz'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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 "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency 'test-unit'
|
24
|
+
end
|
data/lib/iz.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'iz/version'
|
2
|
+
|
3
|
+
require 'iz/credit_card'
|
4
|
+
require 'iz/hexadecimal'
|
5
|
+
require 'iz/binary'
|
6
|
+
require 'iz/mac'
|
7
|
+
|
8
|
+
module Iz
|
9
|
+
def self.credit_card?(cc)
|
10
|
+
Iz::CreditCard.is_credit_card?(cc)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.hexadecimal?(hexadecimal)
|
14
|
+
Iz::Hexadecimal.is_hexadecimal?(hexadecimal)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.binary?(binary)
|
18
|
+
Iz::Binary.is_binary?(binary)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.mac?(mac)
|
22
|
+
Iz::Mac.is_mac?(mac)
|
23
|
+
end
|
24
|
+
end
|
data/lib/iz/binary.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Iz
|
2
|
+
class Binary
|
3
|
+
REGEX = /^[01]+$/
|
4
|
+
|
5
|
+
attr_accessor :value
|
6
|
+
|
7
|
+
def initialize(binary)
|
8
|
+
self.value = binary
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
Iz::Binary.is_binary?(value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.is_binary?(value)
|
16
|
+
value.to_s =~ REGEX
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Iz
|
2
|
+
class CreditCard
|
3
|
+
REGEX = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/
|
4
|
+
|
5
|
+
attr_accessor :number
|
6
|
+
|
7
|
+
def initialize(credit_card_number)
|
8
|
+
self.number = credit_card_number
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
Iz::CreditCard.is_credit_card?(number)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.is_credit_card?(number)
|
16
|
+
number.to_s =~ REGEX
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Iz
|
2
|
+
class Hexadecimal
|
3
|
+
REGEX = /^[0-9a-f]+$/i
|
4
|
+
|
5
|
+
attr_accessor :value
|
6
|
+
|
7
|
+
def initialize(hexadecimal)
|
8
|
+
self.value = hexadecimal
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
Iz::Hexadecimal.is_hexadecimal?(value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.is_hexadecimal?(value)
|
16
|
+
value.to_s =~ REGEX
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/iz/mac.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Iz
|
2
|
+
class Mac
|
3
|
+
REGEX = /^(([0-9A-Fa-f]{2}[:\.-]){5}([0-9A-Fa-f]{2}))|([0-9A-Fa-f]{12})|(([0-9A-Fa-f]{4}[:\.-]){2}([0-9A-Fa-f]{4}))$/
|
4
|
+
|
5
|
+
attr_accessor :value
|
6
|
+
|
7
|
+
def initialize(mac)
|
8
|
+
self.value = mac
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
Iz::Mac.is_mac?(value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.is_mac?(value)
|
16
|
+
value.to_s =~ REGEX
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/iz/version.rb
ADDED
data/test/test_binary.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'iz'
|
3
|
+
|
4
|
+
class TestBinary < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def valid_binary_values
|
7
|
+
['0', '1', '1111', '0000000', '1010111100101']
|
8
|
+
end
|
9
|
+
|
10
|
+
def invalid_binary_values
|
11
|
+
[nil, false, -1, '', '1112', 'g', '10101a']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_binary_values_return_true
|
15
|
+
valid_binary_values.each do |hex|
|
16
|
+
assert Iz.binary?(hex)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_invalid_binary_values_return_false
|
21
|
+
invalid_binary_values.each do |hex|
|
22
|
+
assert !Iz.binary?(hex)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'iz'
|
3
|
+
|
4
|
+
class TestCreditCard < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def valid_credit_cards
|
7
|
+
['4242424242424242']
|
8
|
+
end
|
9
|
+
|
10
|
+
def invalid_credit_cards
|
11
|
+
[nil, false, -1, '', ' ', '424242424242']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_credit_card_values_return_true
|
15
|
+
valid_credit_cards.each do |cc|
|
16
|
+
assert Iz.credit_card?(cc)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_invalid_credit_card_values_return_false
|
21
|
+
invalid_credit_cards.each do |cc|
|
22
|
+
assert !Iz.credit_card?(cc)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'iz'
|
3
|
+
|
4
|
+
class TestHexadecimal < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def valid_hexadecimals
|
7
|
+
['123', '1bc', 'AB99', '8098098AbCdEf']
|
8
|
+
end
|
9
|
+
|
10
|
+
def invalid_hexadecimals
|
11
|
+
[nil, false, -1, '', ' ', 'g', '123g']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_hexadecimal_values_return_true
|
15
|
+
valid_hexadecimals.each do |hex|
|
16
|
+
assert Iz.hexadecimal?(hex)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_invalid_hexadecimal_values_return_false
|
21
|
+
invalid_hexadecimals.each do |hex|
|
22
|
+
assert !Iz.hexadecimal?(hex)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/test_mac.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'iz'
|
3
|
+
|
4
|
+
class TestMac < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def valid_mac_values
|
7
|
+
['aabbccddeeff', 'aa:bb:cc:dd:ee:ff', '11-22-33-44-55-66']
|
8
|
+
end
|
9
|
+
|
10
|
+
def invalid_mac_values
|
11
|
+
[nil, false, -1, '', '1112', 'g', '10101a']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_mac_values_return_true
|
15
|
+
valid_mac_values.each do |mac|
|
16
|
+
puts mac.inspect
|
17
|
+
assert Iz.mac?(mac)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_that_invalid_mac_values_return_false
|
22
|
+
invalid_mac_values.each do |mac|
|
23
|
+
assert !Iz.mac?(mac)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Otander
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-05 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: test-unit
|
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: Iz provides an API for type checking objects.
|
56
|
+
email:
|
57
|
+
- johnotander@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- iz.gemspec
|
69
|
+
- lib/iz.rb
|
70
|
+
- lib/iz/binary.rb
|
71
|
+
- lib/iz/credit_card.rb
|
72
|
+
- lib/iz/hexadecimal.rb
|
73
|
+
- lib/iz/mac.rb
|
74
|
+
- lib/iz/version.rb
|
75
|
+
- test/test_binary.rb
|
76
|
+
- test/test_credit_card.rb
|
77
|
+
- test/test_hexadecimal.rb
|
78
|
+
- test/test_mac.rb
|
79
|
+
homepage: https://github.com/johnotander/iz
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: All your type checking in one place.
|
103
|
+
test_files:
|
104
|
+
- test/test_binary.rb
|
105
|
+
- test/test_credit_card.rb
|
106
|
+
- test/test_hexadecimal.rb
|
107
|
+
- test/test_mac.rb
|