Permalink
Browse files

simplify parsed_links and parsed_images

  • Loading branch information...
jaimeiniesta committed Dec 1, 2012
1 parent 2323680 commit c4ecca3fa254c88d48db658cab40cd9258497983
Showing with 3 additions and 7 deletions.
  1. +2 −6 lib/meta_inspector/scraper.rb
  2. +1 −1 spec/spec_helper.rb
@@ -198,15 +198,11 @@ def get_meta_name_or_property(element)
end
def parsed_links
- @parsed_links ||= parsed_document.search("//a") \
- .map {|link| link.attributes["href"] \
- .to_s.strip}.uniq rescue []
+ @parsed_links ||= parsed_document.search("//a/@href").map { |a| a.value.strip }.reject { |s| s.empty? }.uniq
end
def parsed_images
- @parsed_images ||= parsed_document.search('//img') \
- .reject{|i| (i.attributes['src'].nil? || i.attributes['src'].value.empty?) } \
- .map{ |i| i.attributes['src'].value }.uniq
+ @parsed_images ||= parsed_document.search('//img/@src').map{ |i| i.value.strip }.reject { |s| s.empty? }.uniq
end
# Stores the error for later inspection
View
@@ -32,7 +32,7 @@ def fixture_file(filename)
FakeWeb.register_uri(:get, "http://www.youtube.com/watch?v=iaGSSrp49uc", :response => fixture_file("youtube.response"))
FakeWeb.register_uri(:get, "http://markupvalidator.com/faqs", :response => fixture_file("markupvalidator_faqs.response"))
FakeWeb.register_uri(:get, "https://twitter.com/markupvalidator", :response => fixture_file("twitter_markupvalidator.response"))
-FakeWeb.register_uri(:get, "https://example.com/empty", :response => fixture_file("empty_page.response"))
+FakeWeb.register_uri(:get, "http://example.com/empty", :response => fixture_file("empty_page.response"))
FakeWeb.register_uri(:get, "http://international.com", :response => fixture_file("international.response"))
FakeWeb.register_uri(:get, "http://charset000.com", :response => fixture_file("charset_000.response"))
FakeWeb.register_uri(:get, "http://charset001.com", :response => fixture_file("charset_001.response"))

0 comments on commit c4ecca3

Please sign in to comment.