Class: TopStockMovers::Stocks
- Inherits:
-
Object
- Object
- TopStockMovers::Stocks
- Defined in:
- lib/top_stock_movers/stocks.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#change ⇒ Object
Returns the value of attribute change.
-
#market_cap ⇒ Object
Returns the value of attribute market_cap.
-
#name ⇒ Object
Returns the value of attribute name.
-
#percent_change ⇒ Object
Returns the value of attribute percent_change.
-
#price ⇒ Object
Returns the value of attribute price.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#sector ⇒ Object
Returns the value of attribute sector.
-
#ticker_symbol ⇒ Object
Returns the value of attribute ticker_symbol.
-
#url ⇒ Object
Returns the value of attribute url.
-
#volume ⇒ Object
Returns the value of attribute volume.
Class Method Summary collapse
Instance Attribute Details
#change ⇒ Object
Returns the value of attribute change.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def change @change end |
#market_cap ⇒ Object
Returns the value of attribute market_cap.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def market_cap @market_cap end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def name @name end |
#percent_change ⇒ Object
Returns the value of attribute percent_change.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def percent_change @percent_change end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def price @price end |
#rating ⇒ Object
Returns the value of attribute rating.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def @rating end |
#sector ⇒ Object
Returns the value of attribute sector.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def sector @sector end |
#ticker_symbol ⇒ Object
Returns the value of attribute ticker_symbol.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def ticker_symbol @ticker_symbol end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def url @url end |
#volume ⇒ Object
Returns the value of attribute volume.
2 3 4 |
# File 'lib/top_stock_movers/stocks.rb', line 2 def volume @volume end |
Class Method Details
.all ⇒ Object
6 7 8 |
# File 'lib/top_stock_movers/stocks.rb', line 6 def self.all @@all end |
.scrape_tradingview(category) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/top_stock_movers/stocks.rb', line 10 def self.scrape_tradingview(category) doc = Nokogiri::HTML(open("https://www.tradingview.com/markets/stocks-usa/market-movers-#{category}/")) doc.css('body div div#js-category-content div div div div#js-screener-container div table tbody tr').each do |row| stock = self.new stock.url = "https://www.tradingview.com#{row.css('a').attr('href').value}" stock_info = row.css('td').collect{|td| td.text} stock.ticker_symbol = stock_info[0].split("\n\t\t\t\t\t\t").reject{|c| c.empty?}[0] stock.name = stock_info[0].split("\n\t\t\t\t\t\t").reject{|c| c.empty?}[1].gsub(/INC|LTD|PLC|3X|LLC|BOND|SPONSORED|\s{2,}|[,(-]/, "++").split("++")[0] stock.price = stock_info[1].to_f stock.percent_change = stock_info[2].to_f stock.change = stock_info[3].to_f stock. = stock_info[4] stock.volume = stock_info[5].to_f stock.market_cap = stock_info[6].to_f.round(1) stock.sector = stock_info[10] @@all << stock end end |