class BnetScraper::Starcraft2::GrandmasterScraper

Constants

REGIONS

Attributes

players[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/bnet_scraper/starcraft2/grandmaster_scraper.rb, line 7
def initialize options = {}
  @players = []
  if REGIONS.include? options[:region]
    @url = "http://#{options[:region]}.battle.net/sc2/en/ladder/grandmaster/heart-of-the-swarm"
  else
    raise "Invalid Region #{options[:region]}"
  end
end

Public Instance Methods

get_grandmasters(html) click to toggle source
# File lib/bnet_scraper/starcraft2/grandmaster_scraper.rb, line 32
def get_grandmasters html
  html.css("#ladder tbody tr").each do |player_data|
    player_cells = player_data.css("td[class='align-center']")
    player = {
      name: player_data.css("td a").inner_text.strip,
      points: player_cells[2].inner_text,
      wins: player_cells[3].inner_text,
      losses: player_cells[4].inner_text,
      race: player_data.css("td a").attr('class').value.sub('race-', ''),
      rank: player_cells[1].inner_text.strip
    }

    @players << player
  end
end
retrieve_data() click to toggle source
# File lib/bnet_scraper/starcraft2/grandmaster_scraper.rb, line 24
def retrieve_data
  response = Faraday.get @url

  if response.success?
    Nokogiri::HTML(response.body)
  end
end
scrape() click to toggle source
# File lib/bnet_scraper/starcraft2/grandmaster_scraper.rb, line 16
def scrape
  html = retrieve_data    

  get_grandmasters html

  @players
end