Class: StockScraper::Stock
- Inherits:
-
Object
- Object
- StockScraper::Stock
- Defined in:
- lib/stock_scraper/stock.rb
Instance Attribute Summary collapse
-
#change_percent ⇒ Object
Returns the value of attribute change_percent.
-
#last_price ⇒ Object
Returns the value of attribute last_price.
-
#market_time ⇒ Object
Returns the value of attribute market_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Class Method Summary collapse
Instance Attribute Details
#change_percent ⇒ Object
Returns the value of attribute change_percent.
2 3 4 |
# File 'lib/stock_scraper/stock.rb', line 2 def change_percent @change_percent end |
#last_price ⇒ Object
Returns the value of attribute last_price.
2 3 4 |
# File 'lib/stock_scraper/stock.rb', line 2 def last_price @last_price end |
#market_time ⇒ Object
Returns the value of attribute market_time.
2 3 4 |
# File 'lib/stock_scraper/stock.rb', line 2 def market_time @market_time end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/stock_scraper/stock.rb', line 2 def name @name end |
#symbol ⇒ Object
Returns the value of attribute symbol.
2 3 4 |
# File 'lib/stock_scraper/stock.rb', line 2 def symbol @symbol end |
Class Method Details
.scrape_yahoo ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/stock_scraper/stock.rb', line 4 def self.scrape_yahoo doc = Nokogiri::HTML(open("https://finance.yahoo.com/trending-tickers/")) scraped_stocks = [] doc.css("tbody tr").each do |column| stock_obj = self.new stock_obj.symbol = column.css("td.data-col0")[0].children[0].values[2] stock_obj.name = column.css("td.data-col0")[0].children[0].values[1] stock_obj.last_price = column.css("td.data-col2")[0].children.inner_text stock_obj.market_time = column.css("td.data-col3")[0].children.inner_text stock_obj.change_percent = column.css("td.data-col5")[0].children.inner_text scraped_stocks << stock_obj end scraped_stocks end |