lib/leaderboard/leaderboard.rb
###
# The core of the scrape, there is a timeout.
# If any error occurs the method returns false.
The core of the scrape, there is a timeout.
If any error occurs the method returns false.
The core of the scrape there is a timeout . If any error occurs the method returns false .
def scrape_core(timeout = 5)
    begin
      url = "https://us.battle.net/d3/en/rankings/season/#{@season}/rift-#{@hero}"
      doc = Timeout.timeout(timeout) do
        Nokogiri::HTML(open(url), nil, Encoding::UTF_8.to_s)
      end
      unless doc.nil?
        leaders_unformated = doc.xpath('//*/table/tbody/tr//*/a/@href')
        @ladder.clear
        leaders_unformated.each_with_index do |player, index|
            @ladder << player.value
            @ladder[index].slice!('/d3/en/profile/')
            @ladder[index].slice!('/')
        end
      end
      return true
    rescue
      return false
    end
  end
def scrape_core ( timeout = 5 ) begin url = "https://us.battle.net/d3/en/rankings/season/#{@season}/rift-#{@hero}" doc = Timeout . timeout ( timeout ) do Nokogiri :: HTML ( open ( url ) , nil , Encoding :: UTF_8 . to_s ) end unless doc . nil? leaders_unformated = doc . xpath ( '//*/table/tbody/tr//*/a/@href' ) @ladder . clear leaders_unformated . each_with_index do | player , index | @ladder << player . value @ladder [ index ] . slice! ( '/d3/en/profile/' ) @ladder [ index ] . slice! ( '/' ) end end return true rescue return false end end
The core of the scrape, there is a timeout.
The core of the scrape there is a timeout .
# Use this as a catch all for any exceptions. # In my testing scraping can sometimes take too long.
timeout
<not_specific>