postrank-uri 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/postrank-uri.rb +2 -2
- data/lib/postrank-uri/version.rb +1 -1
- data/spec/postrank-uri_spec.rb +8 -10
- metadata +2 -2
data/lib/postrank-uri.rb
CHANGED
@@ -83,7 +83,7 @@ module PostRank
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def extract_href(text, host = nil)
|
86
|
-
urls =
|
86
|
+
urls = []
|
87
87
|
Nokogiri.HTML(text).search('a').each do |a|
|
88
88
|
begin
|
89
89
|
url = normalize(c18n(unescape(a.attr('href'))))
|
@@ -92,7 +92,7 @@ module PostRank
|
|
92
92
|
url.host = host
|
93
93
|
end
|
94
94
|
|
95
|
-
urls[url.to_s
|
95
|
+
urls.push [url.to_s, a.text]
|
96
96
|
rescue
|
97
97
|
next
|
98
98
|
end
|
data/lib/postrank-uri/version.rb
CHANGED
data/spec/postrank-uri_spec.rb
CHANGED
@@ -186,14 +186,13 @@ describe PostRank::URI do
|
|
186
186
|
|
187
187
|
context "href extract" do
|
188
188
|
it "should extract links from html text" do
|
189
|
-
|
190
|
-
l.keys.size.should == 2
|
189
|
+
g,b = PostRank::URI.extract_href("<a href='google.com'>link to google</a> with text <a href='b.com'>stuff</a>")
|
191
190
|
|
192
|
-
|
193
|
-
|
191
|
+
g.first.should == 'http://google.com/'
|
192
|
+
b.first.should == 'http://b.com/'
|
194
193
|
|
195
|
-
|
196
|
-
|
194
|
+
g.last.should == 'link to google'
|
195
|
+
b.last.should == 'stuff'
|
197
196
|
end
|
198
197
|
|
199
198
|
it "should handle empty hrefs" do
|
@@ -210,10 +209,9 @@ describe PostRank::URI do
|
|
210
209
|
end
|
211
210
|
|
212
211
|
it "should resolve relative paths if host is provided" do
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
l['http://igvita.com/stuff'].should == 'link to stuff'
|
212
|
+
i = PostRank::URI.extract_href("<a href='/stuff'>link to stuff</a>", "igvita.com").first
|
213
|
+
i.first.should == 'http://igvita.com/stuff'
|
214
|
+
i.last.should == 'link to stuff'
|
217
215
|
end
|
218
216
|
end
|
219
217
|
end
|