iz 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69f9f599a28127cc5153125b7a301b36d7f84ee1
4
- data.tar.gz: adae005f1fb5f8dab47c2dd2622287f3bdb92354
3
+ metadata.gz: d056d00e90c38e12c3b38407f049ca845dfefb73
4
+ data.tar.gz: a67ceb3e8a9575fe824c05a4fb822a4d0bab5a6b
5
5
  SHA512:
6
- metadata.gz: b8c73b0004ea2510d88e468d05f12a04d0264fc15d2acf694bde6e0ce96456249ca54f5125d8d025a56d3f9d944c4425ac49724dee3bce84ce3a14cac1994b15
7
- data.tar.gz: 09de25c0e248fb7c9ff9d7206af6c8994cbfc46da0cd52d3dc8406cb4816e08da45f66936a6dc210b454e62c6462f896c0cddcaec7cf1fa128a494bda040383b
6
+ metadata.gz: 54e09786c5ff94f2daf457d74ed33d181a74f483208aeb0a2142bf563cdd11ac370f6f36637da0303452bb0a34ea4f9b6d800a6414e4834a816f7fe5d3052d2e
7
+ data.tar.gz: 16e8af40bd067c06e1f05f207cbcf1e0a692d5364d988fec18b4c727fc1ebc215dba9e359083066f044f3b60b6c17a8f8bc6f8bffeecda9949c9f1504545727b
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+
16
+ *.gem
data/README.md CHANGED
@@ -38,13 +38,19 @@ Iz.binary?('foo') # => false
38
38
 
39
39
  Iz.hexadecimal?(0x34) # => true
40
40
  Iz.hexadecimal?('abcdef123') # => true
41
+
42
+ Iz.url?('google.com') # => false
43
+ Iz.url?('//google.com') # => true
44
+ Iz.url?('http://google.com') # => true
45
+
46
+ Iz.alphanumeric?('1234ABCD') # => true
47
+
48
+ Iz.phone_number?('1234567') # => true
41
49
  ```
42
50
 
43
51
  ## Upcoming support
44
52
 
45
53
  ```ruby
46
- Iz.phone_number?('1234567') # => true
47
-
48
54
  Iz.zip_code?('12345', :us) # => true
49
55
 
50
56
  Iz.ip?(nil) # => false
@@ -58,9 +64,6 @@ Iz.hex_color?('#fff') # => true
58
64
  Iz.rgb_color?('rgb(123, 123, 123)') # => true
59
65
 
60
66
  Iz.hsl_color?('foobar') # => false
61
-
62
- Iz.url?('google.com') # => true
63
- Iz.url?('http://google.com') # => true
64
67
  ```
65
68
 
66
69
  ## Acknowledgements
data/lib/iz.rb CHANGED
@@ -1,24 +1,39 @@
1
1
  require 'iz/version'
2
2
 
3
+ require 'iz/alphanumeric'
4
+ require 'iz/phone_number'
3
5
  require 'iz/credit_card'
4
6
  require 'iz/hexadecimal'
5
7
  require 'iz/binary'
6
8
  require 'iz/mac'
9
+ require 'iz/url'
7
10
 
8
11
  module Iz
9
12
  def self.credit_card?(cc)
10
- Iz::CreditCard.is_credit_card?(cc)
13
+ !!Iz::CreditCard.is_credit_card?(cc)
11
14
  end
12
15
 
13
16
  def self.hexadecimal?(hexadecimal)
14
- Iz::Hexadecimal.is_hexadecimal?(hexadecimal)
17
+ !!Iz::Hexadecimal.is_hexadecimal?(hexadecimal)
15
18
  end
16
19
 
17
20
  def self.binary?(binary)
18
- Iz::Binary.is_binary?(binary)
21
+ !!Iz::Binary.is_binary?(binary)
19
22
  end
20
23
 
21
24
  def self.mac?(mac)
22
- Iz::Mac.is_mac?(mac)
25
+ !!Iz::Mac.is_mac?(mac)
26
+ end
27
+
28
+ def self.url?(url)
29
+ !!Iz::Url.is_url?(url)
30
+ end
31
+
32
+ def self.alphanumeric?(alpha)
33
+ !!Iz::Alphanumeric.is_alphanumeric?(alpha)
34
+ end
35
+
36
+ def self.phone_number?(phone_number)
37
+ !!Iz::PhoneNumber.is_phone_number?(phone_number)
23
38
  end
24
39
  end
@@ -0,0 +1,20 @@
1
+ module Iz
2
+ class Alphanumeric
3
+ REGEX = /^[a-z0-9]+$/i
4
+
5
+ attr_accessor :value
6
+
7
+ def initialize(alphanumeric)
8
+ self.value = alphanumeric
9
+ end
10
+
11
+ def valid?
12
+ !!Iz::Alphanumeric.is_alphanumeric?(value)
13
+ end
14
+
15
+ def self.is_alphanumeric?(value)
16
+ return false unless value
17
+ value.to_s =~ REGEX
18
+ end
19
+ end
20
+ end
@@ -9,10 +9,11 @@ module Iz
9
9
  end
10
10
 
11
11
  def valid?
12
- Iz::Binary.is_binary?(value)
12
+ !!Iz::Binary.is_binary?(value)
13
13
  end
14
14
 
15
15
  def self.is_binary?(value)
16
+ return false unless value
16
17
  value.to_s =~ REGEX
17
18
  end
18
19
  end
@@ -2,18 +2,19 @@ module Iz
2
2
  class CreditCard
3
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
4
 
5
- attr_accessor :number
5
+ attr_accessor :value
6
6
 
7
7
  def initialize(credit_card_number)
8
- self.number = credit_card_number
8
+ self.value = credit_card_number
9
9
  end
10
10
 
11
11
  def valid?
12
- Iz::CreditCard.is_credit_card?(number)
12
+ !!Iz::CreditCard.is_credit_card?(value)
13
13
  end
14
14
 
15
- def self.is_credit_card?(number)
16
- number.to_s =~ REGEX
15
+ def self.is_credit_card?(value)
16
+ return false unless value
17
+ value.to_s =~ REGEX
17
18
  end
18
19
  end
19
20
  end
@@ -9,7 +9,7 @@ module Iz
9
9
  end
10
10
 
11
11
  def valid?
12
- Iz::Hexadecimal.is_hexadecimal?(value)
12
+ !!Iz::Hexadecimal.is_hexadecimal?(value)
13
13
  end
14
14
 
15
15
  def self.is_hexadecimal?(value)
@@ -9,10 +9,11 @@ module Iz
9
9
  end
10
10
 
11
11
  def valid?
12
- Iz::Mac.is_mac?(value)
12
+ !!Iz::Mac.is_mac?(value)
13
13
  end
14
14
 
15
15
  def self.is_mac?(value)
16
+ return false unless value
16
17
  value.to_s =~ REGEX
17
18
  end
18
19
  end
@@ -0,0 +1,20 @@
1
+ module Iz
2
+ class PhoneNumber
3
+ REGEX = /^(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?$/
4
+
5
+ attr_accessor :value
6
+
7
+ def initialize(phone_number)
8
+ self.value = phone_number
9
+ end
10
+
11
+ def valid?
12
+ !!Iz::PhoneNumber.is_phone_number?(value)
13
+ end
14
+
15
+ def self.is_phone_number?(value)
16
+ return false unless value
17
+ value.to_s =~ REGEX
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Iz
2
+ class Url
3
+ REGEX = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/i
4
+
5
+ attr_accessor :value
6
+
7
+ def initialize(url)
8
+ self.value = url
9
+ end
10
+
11
+ def valid?
12
+ !!Iz::Url.is_url?(value)
13
+ end
14
+
15
+ def self.is_url?(value)
16
+ return false unless value
17
+ value.to_s =~ REGEX
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Iz
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require 'iz'
3
+
4
+ class TestAlphanumeric < Test::Unit::TestCase
5
+
6
+ def valid_alphanumeric_values
7
+ ['abc123', 'ABC123', '123', 'A', :foo]
8
+ end
9
+
10
+ def invalid_alphanumeric_values
11
+ [nil, false, -1, '', 'http://google', 'https://google', 'www.google', 'foo!']
12
+ end
13
+
14
+ def test_that_alphanumeric_values_return_true
15
+ valid_alphanumeric_values.each do |alphanumeric|
16
+ assert Iz.alphanumeric?(alphanumeric)
17
+ end
18
+ end
19
+
20
+ def test_that_invalid_alphanumeric_values_return_false
21
+ invalid_alphanumeric_values.each do |alphanumeric|
22
+ assert !Iz.alphanumeric?(alphanumeric)
23
+ end
24
+ end
25
+ end
@@ -13,7 +13,6 @@ class TestMac < Test::Unit::TestCase
13
13
 
14
14
  def test_that_mac_values_return_true
15
15
  valid_mac_values.each do |mac|
16
- puts mac.inspect
17
16
  assert Iz.mac?(mac)
18
17
  end
19
18
  end
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require 'iz'
3
+
4
+ class TestPhoneNumber < Test::Unit::TestCase
5
+
6
+ def valid_phone_numbers
7
+ ['(123) 456-7890', '11234567890', '1 123 456 7890', '123-456-7890']
8
+ end
9
+
10
+ def invalid_phone_numbers
11
+ [nil, false, -1, '123456']
12
+ end
13
+
14
+ def test_that_phone_numbers_return_true
15
+ valid_phone_numbers.each do |phone_number|
16
+ assert Iz.phone_number?(phone_number)
17
+ end
18
+ end
19
+
20
+ def test_that_invalid_phone_numbers_return_false
21
+ invalid_phone_numbers.each do |phone_number|
22
+ assert !Iz.phone_number?(phone_number)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require 'iz'
3
+
4
+ class TestUrl < Test::Unit::TestCase
5
+
6
+ def valid_urls
7
+ ['http://google.com', 'https://google.com', 'http://www.foo.bar', 'https://foo.io', '//google.com.uk']
8
+ end
9
+
10
+ def invalid_urls
11
+ [nil, false, -1, '', '1112', 'g', '10101a', 'http://google', 'https://google', 'www.google']
12
+ end
13
+
14
+ def test_that_urls_return_true
15
+ valid_urls.each do |url|
16
+ assert Iz.url?(url)
17
+ end
18
+ end
19
+
20
+ def test_that_invalid_urls_return_false
21
+ invalid_urls.each do |url|
22
+ assert !Iz.url?(url)
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Otander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,15 +67,21 @@ files:
67
67
  - Rakefile
68
68
  - iz.gemspec
69
69
  - lib/iz.rb
70
+ - lib/iz/alphanumeric.rb
70
71
  - lib/iz/binary.rb
71
72
  - lib/iz/credit_card.rb
72
73
  - lib/iz/hexadecimal.rb
73
74
  - lib/iz/mac.rb
75
+ - lib/iz/phone_number.rb
76
+ - lib/iz/url.rb
74
77
  - lib/iz/version.rb
78
+ - test/test_alphanumeric.rb
75
79
  - test/test_binary.rb
76
80
  - test/test_credit_card.rb
77
81
  - test/test_hexadecimal.rb
78
82
  - test/test_mac.rb
83
+ - test/test_phone_number.rb
84
+ - test/test_url.rb
79
85
  homepage: https://github.com/johnotander/iz
80
86
  licenses:
81
87
  - MIT
@@ -101,7 +107,10 @@ signing_key:
101
107
  specification_version: 4
102
108
  summary: All your type checking in one place.
103
109
  test_files:
110
+ - test/test_alphanumeric.rb
104
111
  - test/test_binary.rb
105
112
  - test/test_credit_card.rb
106
113
  - test/test_hexadecimal.rb
107
114
  - test/test_mac.rb
115
+ - test/test_phone_number.rb
116
+ - test/test_url.rb