Class: Roster

Inherits:
Object
  • Object
show all
Defined in:
lib/ow_heroes_roster/roster.rb

Class Method Summary collapse

Class Method Details

.scrape_roster_pageObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ow_heroes_roster/roster.rb', line 8

def self.scrape_roster_page
  html = open("https://playoverwatch.com/en-us/heroes/")
  heroes = []
  doc = Nokogiri::HTML(html)
  doc.css(".hero-portrait-detailed-container").each do |card|
    hero_name = card.css(".container .portrait-title").text
    if hero_name.include?("ú")
      hero_name = hero_name.gsub(/ú/, 'u')
    elsif hero_name.include?("ö")
      hero_name = hero_name.gsub(/ö/, 'o')
    end
    hero_url = card.css("a").attr("href").value
    heroes << {name: hero_name.upcase, url: hero_url}
  end
  heroes.each do |hero|
    hero = Hero.new(hero[:name], hero[:url])
  end

end