zeke-monkey_patches 0.1.16 → 0.1.17
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.
- data/VERSION.yml +1 -1
- data/lib/monkey_patches.rb +28 -3
- data/spec/monkey_patches_spec.rb +5 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/monkey_patches.rb
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
module RFC822
|
2
|
+
EmailAddress = begin
|
3
|
+
qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
|
4
|
+
dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
|
5
|
+
atom_middle = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' +
|
6
|
+
'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
|
7
|
+
atom_edge = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c-\\x2e\\x3a-' +
|
8
|
+
'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]'
|
9
|
+
atom = "(?:#{atom_edge}{1,2}|#{atom_edge}#{atom_middle}#{atom_edge})"
|
10
|
+
quoted_pair = '\\x5c[\\x00-\\x7f]'
|
11
|
+
domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d"
|
12
|
+
quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22"
|
13
|
+
domain_ref = atom
|
14
|
+
sub_domain = "(?:[a-zA-Z0-9][\-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z0-9]+)"
|
15
|
+
word = "(?:#{atom}|#{quoted_string})"
|
16
|
+
domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
|
17
|
+
local_part = "#{word}(?:\\x2e#{word})*"
|
18
|
+
addr_spec = "#{local_part}\\x40#{domain}"
|
19
|
+
pattern = /\A#{addr_spec}\z/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
1
23
|
class Object
|
2
24
|
|
3
25
|
unless method_defined? "blank?"
|
@@ -16,7 +38,6 @@ class Object
|
|
16
38
|
send method if respond_to? method
|
17
39
|
end
|
18
40
|
end
|
19
|
-
|
20
41
|
|
21
42
|
end
|
22
43
|
|
@@ -117,6 +138,11 @@ class String
|
|
117
138
|
!self.match(/https?:\/\/([^\/]+)(.*)/).nil?
|
118
139
|
end
|
119
140
|
|
141
|
+
# Returns true or false depending on whether a string appears to be an email address
|
142
|
+
def valid_email?
|
143
|
+
!self.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$/i).nil?
|
144
|
+
end
|
145
|
+
|
120
146
|
# Removes tab characters and instances of more than one space
|
121
147
|
def remove_whitespace
|
122
148
|
self.gnix("\t").split(" ").remove_blanks.join(" ")
|
@@ -239,5 +265,4 @@ class Array
|
|
239
265
|
self[0..self.size-2]
|
240
266
|
end
|
241
267
|
|
242
|
-
end
|
243
|
-
|
268
|
+
end
|
data/spec/monkey_patches_spec.rb
CHANGED
@@ -85,6 +85,11 @@ describe "MonkeyPatches" do
|
|
85
85
|
"testsite.com".valid_url?.should == false
|
86
86
|
end
|
87
87
|
|
88
|
+
it "validates emails" do
|
89
|
+
["bob.the.boss@moma.museum", "123@big.domain.madness.info", "test@foo.com"].all?{|e| e.valid_email? }.should == true
|
90
|
+
["test@foo", "text", ""].any?{|e| e.valid_email? }.should == false
|
91
|
+
end
|
92
|
+
|
88
93
|
it "removes whitespace" do
|
89
94
|
"this is a test".remove_whitespace.should == "this is a test"
|
90
95
|
" this \t is also a test ".remove_whitespace.should == "this is also a test"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zeke-monkey_patches
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Sikelianos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|