Class: Snackhack2::WebsiteMeta
- Inherits:
-
Object
- Object
- Snackhack2::WebsiteMeta
- Defined in:
- lib/snackhack2/website_meta.rb
Instance Attribute Summary collapse
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize ⇒ WebsiteMeta
constructor
A new instance of WebsiteMeta.
- #run ⇒ Object
Constructor Details
#initialize ⇒ WebsiteMeta
Returns a new instance of WebsiteMeta.
9 10 11 |
# File 'lib/snackhack2/website_meta.rb', line 9 def initialize() @site = site end |
Instance Attribute Details
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/snackhack2/website_meta.rb', line 7 def site @site end |
Instance Method Details
#description ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/snackhack2/website_meta.rb', line 20 def description begin doc = Nokogiri::HTML(URI.open("https://#{@site}", "User-Agent" => Snackhack2::UA)) if !doc.xpath('/html/head/meta[@name="description"]/@content').to_s.empty? doc.xpath('/html/head/meta[@name="description"]/@content').to_s end #dsp << rescue => e puts "ERROR: #{e}" end end |
#run ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/snackhack2/website_meta.rb', line 13 def run doc = Nokogiri::HTML(URI.open(@site)) posts = doc.xpath('//meta') posts.each do |link| puts "#{link.attributes['name']}: #{link.attributes['content']}" unless link.attributes['name'].nil? end end |