Skip to content

Commit

Permalink
Simplify scrape_meta_data method
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeiniesta committed Dec 1, 2012
1 parent c9dbd86 commit 2113ec2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/meta_inspector/scraper.rb
Expand Up @@ -190,19 +190,20 @@ def scrape_meta_data
@data.meta!.name! @data.meta!.name!
@data.meta!.property! @data.meta!.property!
parsed_document.xpath("//meta").each do |element| parsed_document.xpath("//meta").each do |element|
if element.attributes["content"] get_meta_name_or_property(element)
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
end end
end 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 def parsed_links
@parsed_links ||= parsed_document.search("//a") \ @parsed_links ||= parsed_document.search("//a") \
.map {|link| link.attributes["href"] \ .map {|link| link.attributes["href"] \
Expand Down

0 comments on commit 2113ec2

Please sign in to comment.