superstring 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/superstring.rb +13 -16
- data/lib/superstring/version.rb +1 -1
- data/spec/superstring_spec.rb +28 -18
- metadata +2 -2
data/lib/superstring.rb
CHANGED
@@ -94,23 +94,20 @@ class ::String
|
|
94
94
|
safer
|
95
95
|
end
|
96
96
|
|
97
|
-
DOMAIN_SEGMENT_PATTERN = "[a-z0-9][a-z0-9-]+"
|
98
|
-
URI_PATTERN =
|
99
|
-
%r{
|
100
|
-
^
|
101
|
-
\s* # optional leading whitespace
|
102
|
-
(?:[a-z]+:)? # optional protocol, eg http:
|
103
|
-
// # required //
|
104
|
-
(?:www\.)? # 'www.' is ignored
|
105
|
-
(
|
106
|
-
#{DOMAIN_SEGMENT_PATTERN} # first domain segment
|
107
|
-
(?:\.#{DOMAIN_SEGMENT_PATTERN})+ # one or more additional domain segments
|
108
|
-
)
|
109
|
-
(?:/|$) # followed by a '/' or end of line
|
110
|
-
}ix
|
111
|
-
|
112
97
|
def domain
|
113
|
-
|
98
|
+
host_without_www
|
99
|
+
end
|
100
|
+
|
101
|
+
def host_without_www
|
102
|
+
host.gsub(/^www./, '') if host
|
103
|
+
end
|
104
|
+
|
105
|
+
def host
|
106
|
+
uri.host if uri
|
107
|
+
end
|
108
|
+
|
109
|
+
def uri
|
110
|
+
URI.parse self rescue nil
|
114
111
|
end
|
115
112
|
|
116
113
|
def strip_lines!
|
data/lib/superstring/version.rb
CHANGED
data/spec/superstring_spec.rb
CHANGED
@@ -46,29 +46,32 @@ describe ::String do
|
|
46
46
|
it { "\n\nfoo\nbar\n\n".compact_whitespace.should == "foo bar" }
|
47
47
|
end
|
48
48
|
|
49
|
-
describe "#
|
50
|
-
it { "http://mediawiki.org".
|
51
|
-
it { "http://mediawiki.org/".
|
52
|
-
it { "http://mediawiki.org/foo.html".
|
53
|
-
it { "https://mediawiki.org/".
|
54
|
-
it { "gopher://mediawiki.org/".
|
55
|
-
it { "anyprotocol://mediawiki.org/".
|
56
|
-
it { "//mediawiki.org/".
|
49
|
+
describe "#host" do
|
50
|
+
it { "http://mediawiki.org".host.should == "mediawiki.org"}
|
51
|
+
it { "http://mediawiki.org/".host.should == "mediawiki.org"}
|
52
|
+
it { "http://mediawiki.org/foo.html".host.should == "mediawiki.org"}
|
53
|
+
it { "https://mediawiki.org/".host.should == "mediawiki.org"}
|
54
|
+
it { "gopher://mediawiki.org/".host.should == "mediawiki.org"}
|
55
|
+
it { "anyprotocol://mediawiki.org/".host.should == "mediawiki.org"}
|
56
|
+
it { "//mediawiki.org/".host.should == "mediawiki.org"}
|
57
57
|
context "subdomains" do
|
58
|
-
it { "http://www.mediawiki.org/".
|
59
|
-
it { "http://dance.dance.mediawiki.org/".
|
60
|
-
it { "http://dance-dance-.mediawiki.org/".
|
61
|
-
it { "http://www.dance.dance.mediawiki.org/".
|
58
|
+
it { "http://www.mediawiki.org/".host.should == "www.mediawiki.org"}
|
59
|
+
it { "http://dance.dance.mediawiki.org/".host.should == "dance.dance.mediawiki.org"}
|
60
|
+
it { "http://dance-dance-.mediawiki.org/".host.should == "dance-dance-.mediawiki.org"}
|
61
|
+
it { "http://www.dance.dance.mediawiki.org/".host.should == "www.dance.dance.mediawiki.org"}
|
62
62
|
end
|
63
63
|
context "invalid URIs" do
|
64
|
-
it { "".
|
65
|
-
it { "/mediawiki.org".
|
66
|
-
it { "http://mediawiki.org~~~".
|
67
|
-
it { "http://-illegal-subdomain.mediawiki.org".domain.should == nil }
|
68
|
-
it { "http://-illegal-subdomain.mediawiki.org".domain.should == nil }
|
64
|
+
it { "".host.should == nil }
|
65
|
+
it { "/mediawiki.org".host.should == nil }
|
66
|
+
it { "http://mediawiki.org~~~".host.should == nil }
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
70
|
+
describe "#host_without_www, #domain" do
|
71
|
+
it { "http://www.mediawiki.org/".host_without_www.should == "mediawiki.org"}
|
72
|
+
it { "http://www.mediawiki.org/".domain.should == "mediawiki.org"}
|
73
|
+
end
|
74
|
+
|
72
75
|
describe "#slug" do
|
73
76
|
context "slugs safe for file names, and (arguably) URLs" do
|
74
77
|
it { "".slug(:page).should == "" }
|
@@ -137,4 +140,11 @@ describe ::String do
|
|
137
140
|
it { "".in?(nil).should == false }
|
138
141
|
end
|
139
142
|
|
140
|
-
|
143
|
+
# Note: we don't define this method; it's from the shellescape standard ruby library
|
144
|
+
describe "#shellescape" do
|
145
|
+
it {"Nahko-Bear-(Medicine-for-the-People)-ღ-Aloha-Ke-Akua-ღ".shellescape.should ==
|
146
|
+
"Nahko-Bear-\\(Medicine-for-the-People\\)-\\ღ-Aloha-Ke-Akua-\\ღ" }
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superstring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|