Class: Descartes::Hackernews

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/descartes/modules/hackernews.rb

Instance Method Summary collapse

Instance Method Details

#execute(m, url) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/descartes/modules/hackernews.rb', line 23

def execute(m, url)
	begin
		page = Nokogiri::HTML open(url).read, nil, 'utf-8'

		title = page.at_xpath('//td[@class="title"]/a').text.to_s
		info = page.at_xpath('//td[@class="subtext"]').text.to_s.strip
		comments = info.match(/[0-9]+.comments/).to_s
		info = info.gsub(/\|.*/, "").rstrip
		
		m.reply "[HN] #{title} | #{info} | #{comments}"
	rescue; end
end