class StockInfo::News
Attributes
link[RW]
source[RW]
symbol[RW]
title[RW]
Public Class Methods
get_news(stock)
click to toggle source
# File lib/stock_info/news.rb, line 4 def self.get_news(stock) symbol = stock.symbol stock.news.clear doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}")) i = 0 10.times do article = new article.symbol = symbol sources = doc.css('table#news-table.fullview-news-outer tr span') - doc.css('table#news-table.fullview-news-outer tr span.body-table-news-gain') article.title = doc.css('table#news-table.fullview-news-outer tr')[i].css('.tab-link-news').text article.source = sources[i].text article.link = doc.css('table#news-table.fullview-news-outer tr td a')[i].attribute('href').value stock.news << article i += 1 end end
open_url(link)
click to toggle source
# File lib/stock_info/news.rb, line 36 def self.open_url(link) if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ system "start #{link} -s" elsif RbConfig::CONFIG['host_os'] =~ /darwin/ system "open #{link} -s" elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ system "xdg-open #{link} 2> /dev/null" end end