Class: StockInfo::Stock::News
- Inherits:
-
Object
- Object
- StockInfo::Stock::News
- Defined in:
- lib/stock_info/news.rb
Instance Attribute Summary collapse
-
#link ⇒ Object
Returns the value of attribute link.
-
#source ⇒ Object
Returns the value of attribute source.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
2 3 4 |
# File 'lib/stock_info/news.rb', line 2 def link @link end |
#source ⇒ Object
Returns the value of attribute source.
2 3 4 |
# File 'lib/stock_info/news.rb', line 2 def source @source end |
#symbol ⇒ Object
Returns the value of attribute symbol.
2 3 4 |
# File 'lib/stock_info/news.rb', line 2 def symbol @symbol end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/stock_info/news.rb', line 2 def title @title end |
Class Method Details
.get_news(symbol) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/stock_info/news.rb', line 3 def self.get_news(symbol) news = [] doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}")) i=0 10.times do article = self.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 news << article i+=1 end news end |
.news_menu(stock) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stock_info/news.rb', line 19 def self.(stock) input = nil while input != 'menu' && input != 'exit' stock.print_news puts "Enter the number of an article you would like to open in your web browser, or 'menu' to return to the main menu" input = gets.strip if input.to_i > 0 && input.to_i <= 10 self.open_url(stock.news[(input.to_i) -1].link) elsif input.downcase != 'menu' && input.downcase != 'exit' puts "Enter the number of an article or 'menu'" end end end |
.open_url(link) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stock_info/news.rb', line 33 def self.open_url(link) if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ system "start #{link}" elsif RbConfig::CONFIG['host_os'] =~ /darwin/ system "open #{link}" elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ system "xdg-open #{link}" end end |