Class: StockInfo::Stock
- Inherits:
-
Object
- Object
- StockInfo::Stock
- Defined in:
- lib/stock_info/stock.rb
Defined Under Namespace
Classes: News
Instance Attribute Summary collapse
-
#company ⇒ Object
Returns the value of attribute company.
-
#daily_change ⇒ Object
Returns the value of attribute daily_change.
-
#earnings ⇒ Object
Returns the value of attribute earnings.
-
#news ⇒ Object
Returns the value of attribute news.
-
#optionable ⇒ Object
Returns the value of attribute optionable.
-
#price ⇒ Object
Returns the value of attribute price.
-
#rvol ⇒ Object
Returns the value of attribute rvol.
-
#short_ratio ⇒ Object
Returns the value of attribute short_ratio.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Class Method Summary collapse
Instance Method Summary collapse
- #get_info(symbol) ⇒ Object
-
#initialize(symbol) ⇒ Stock
constructor
A new instance of Stock.
- #print_info ⇒ Object
- #print_news ⇒ Object
Constructor Details
#initialize(symbol) ⇒ Stock
Returns a new instance of Stock.
3 4 5 6 |
# File 'lib/stock_info/stock.rb', line 3 def initialize(symbol) @symbol = symbol self.get_info(symbol) end |
Instance Attribute Details
#company ⇒ Object
Returns the value of attribute company.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def company @company end |
#daily_change ⇒ Object
Returns the value of attribute daily_change.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def daily_change @daily_change end |
#earnings ⇒ Object
Returns the value of attribute earnings.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def earnings @earnings end |
#news ⇒ Object
Returns the value of attribute news.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def news @news end |
#optionable ⇒ Object
Returns the value of attribute optionable.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def optionable @optionable end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def price @price end |
#rvol ⇒ Object
Returns the value of attribute rvol.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def rvol @rvol end |
#short_ratio ⇒ Object
Returns the value of attribute short_ratio.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def short_ratio @short_ratio end |
#symbol ⇒ Object
Returns the value of attribute symbol.
2 3 4 |
# File 'lib/stock_info/stock.rb', line 2 def symbol @symbol end |
Class Method Details
.check_symbol(symbol) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/stock_info/stock.rb', line 7 def self.check_symbol(symbol) begin open("https://finviz.com/quote.ashx?t=#{symbol}").read true rescue => e false end end |
.print_trending ⇒ Object
37 38 39 40 41 |
# File 'lib/stock_info/stock.rb', line 37 def self.print_trending self.trending.each do |stock| puts "#{stock.symbol} - Price: #{stock.price} - Change: #{stock.daily_change} - Relative Volume: #{stock.rvol}" end end |
.trending ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stock_info/stock.rb', line 42 def self.trending trending = [] i = 0 doc = Nokogiri::HTML(open("https://finviz.com/screener.ashx?v=110&s=ta_mostactive")) 10.times do symbol = doc.css("tr.table-dark-row-cp a.screener-link-primary")[i].text i += 1 trending << self.new(symbol) end trending end |
Instance Method Details
#get_info(symbol) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stock_info/stock.rb', line 15 def get_info(symbol) doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}")) self.company = doc.css('table.fullview-title tr')[1].text self.rvol = doc.css("table.snapshot-table2 td.snapshot-td2")[-14].text self.daily_change = doc.css("table.snapshot-table2 td.snapshot-td2")[-1].text self.price = doc.css("table.snapshot-table2 td.snapshot-td2")[-7].text self.optionable = doc.css("table.snapshot-table2 td.snapshot-td2")[-18].text self.short_ratio = doc.css("table.snapshot-table2 td.snapshot-td2")[22].text self.earnings = doc.css("table.snapshot-table2 td.snapshot-td2")[-10].text if self.earnings == '-' self.earnings = "None (ETF)" end end |
#print_info ⇒ Object
34 35 36 |
# File 'lib/stock_info/stock.rb', line 34 def print_info puts "#{self.company} - Price: #{self.price} - Change: #{self.daily_change} - Relative Volume: #{self.rvol} - Earnings Date: #{self.earnings} - Optionable: #{self.optionable} - Short Ratio: #{self.short_ratio}" end |