zeke-monkey_patches 0.1.15 → 0.1.16
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 +10 -2
- data/spec/monkey_patches_spec.rb +7 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/monkey_patches.rb
CHANGED
@@ -57,12 +57,12 @@ class String
|
|
57
57
|
self.gsub(/<\/?[^>]*>/, "")
|
58
58
|
end
|
59
59
|
|
60
|
-
#
|
60
|
+
# Removes first instance of string
|
61
61
|
def nix(string)
|
62
62
|
self.sub(string, "")
|
63
63
|
end
|
64
64
|
|
65
|
-
#
|
65
|
+
# Removes all instances of string
|
66
66
|
def gnix(string)
|
67
67
|
self.gsub(string, "")
|
68
68
|
end
|
@@ -101,15 +101,23 @@ class String
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
# Extracts domain name from a URL
|
104
105
|
def domain
|
105
106
|
url = self.dup
|
106
107
|
url=~(/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/) ? $1 : url
|
107
108
|
end
|
108
109
|
|
110
|
+
# Extracts domain name (sans 'www.') from a URL string
|
109
111
|
def domain_without_www
|
110
112
|
self.domain.remove_http_and_www
|
111
113
|
end
|
112
114
|
|
115
|
+
# Returns true or false depending on whether a string appears to be a URL
|
116
|
+
def valid_url?
|
117
|
+
!self.match(/https?:\/\/([^\/]+)(.*)/).nil?
|
118
|
+
end
|
119
|
+
|
120
|
+
# Removes tab characters and instances of more than one space
|
113
121
|
def remove_whitespace
|
114
122
|
self.gnix("\t").split(" ").remove_blanks.join(" ")
|
115
123
|
end
|
data/spec/monkey_patches_spec.rb
CHANGED
@@ -78,6 +78,13 @@ describe "MonkeyPatches" do
|
|
78
78
|
"not a url".domain.should == "not a url"
|
79
79
|
end
|
80
80
|
|
81
|
+
it "validates urls" do
|
82
|
+
"http://www.google.com".valid_url?.should == true
|
83
|
+
"https://bbc.co.uk/text/123/".valid_url?.should == true
|
84
|
+
"".valid_url?.should == false
|
85
|
+
"testsite.com".valid_url?.should == false
|
86
|
+
end
|
87
|
+
|
81
88
|
it "removes whitespace" do
|
82
89
|
"this is a test".remove_whitespace.should == "this is a test"
|
83
90
|
" 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.16
|
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-
|
12
|
+
date: 2009-06-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|