Permalink
Browse files

Simplify scrape_meta_data method

  • Loading branch information...
1 parent c9dbd86 commit 2113ec2467f15c6f26a8fe21329d47c6b20d04eb @jaimeiniesta committed Dec 1, 2012
Showing with 10 additions and 9 deletions.
  1. +10 −9 lib/meta_inspector/scraper.rb
@@ -190,19 +190,20 @@ def scrape_meta_data
@data.meta!.name!
@data.meta!.property!
parsed_document.xpath("//meta").each do |element|
- if element.attributes["content"]
- if element.attributes["name"]
- @data.meta.name[element.attributes["name"].value.downcase] = element.attributes["content"].value
- end
-
- if element.attributes["property"]
- @data.meta.property[element.attributes["property"].value.downcase] = element.attributes["content"].value
- end
- end
+ get_meta_name_or_property(element)
end
end
end
+ # Store meta tag value, looking at meta name or meta property
+ def get_meta_name_or_property(element)
+ if element.attributes["content"]
+ type = element.attributes["name"] ? "name" : (element.attributes["property"] ? "property" : nil)
+
+ @data.meta.name[element.attributes[type].value.downcase] = element.attributes["content"].value if type
+ end
+ end
+
def parsed_links
@parsed_links ||= parsed_document.search("//a") \
.map {|link| link.attributes["href"] \

0 comments on commit 2113ec2

Please sign in to comment.