Class: StocksInfo::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/stocks-info/scraper.rb

Class Method Summary collapse

Class Method Details

.scrape(ticker) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/stocks-info/scraper.rb', line 3

def self.scrape(ticker)
    ticker.html = Nokogiri::HTML(open("#{ticker.url}"))
    ticker.name = ticker.html.css("#quote-header-info h1").text
    ticker.price = ticker.html.css("#quote-header-info span")[1].text
    ticker.price_change = ticker.html.css("#quote-header-info span")[2].text
    ticker.news = ticker.html.css("#quoteNewsStream-0-Stream a")
end


11
12
13
14
15
16
17
# File 'lib/stocks-info/scraper.rb', line 11

def self.scrape_trending
    html = Nokogiri::HTML(open(StocksInfo::Stocktwits.trending_url))
    all_trending = html.text.scan(/symbol":"\w\w.../)
    all_trending[0..5].each do |symbol|
        StocksInfo::Stocktwits.trending_tickers << symbol.delete!("symbol\":,")
    end
end