Class: Transfermarkt::Club

Inherits:
EntityBase show all
Defined in:
lib/transfermarkt/club.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from EntityBase

#initialize

Constructor Details

This class inherits a constructor from Transfermarkt::EntityBase

Instance Attribute Details

#club_uriObject

Returns the value of attribute club_uri.



3
4
5
# File 'lib/transfermarkt/club.rb', line 3

def club_uri
  @club_uri
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/transfermarkt/club.rb', line 3

def country
  @country
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/transfermarkt/club.rb', line 3

def name
  @name
end

#player_urisObject

Returns the value of attribute player_uris.



3
4
5
# File 'lib/transfermarkt/club.rb', line 3

def player_uris
  @player_uris
end

#playersObject

Returns the value of attribute players.



3
4
5
# File 'lib/transfermarkt/club.rb', line 3

def players
  @players
end

Class Method Details

.fetch_by_club_uri(club_uri, fetch_players = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/transfermarkt/club.rb', line 9

def self.fetch_by_club_uri(club_uri, fetch_players = false)
  req = self.get("/#{club_uri}", headers: {"User-Agent" => UserAgents.rand()})
  if req.code != 200
    nil
  else
    club_html = Nokogiri::HTML(req.parsed_response)
    options = {}
    puts "**** parsing club #{club_uri}"

    options[:club_uri] = club_uri
    options[:name] = club_html.xpath('//*[@class="spielername-profil"]').text.strip
    options[:country] = club_html.xpath('//*[@id="land_select_breadcrumb"]//option[@selected="selected"]').text.strip
    options[:player_uris] = club_html.xpath('//*[@id="yw1"]//table//tr//td[2]//a[contains(@href,"profil")]').collect{|player_html| player_html["href"]}

    options[:players] = []

    if fetch_players
      options[:player_uris].each do |player_uri|
        options[:players] << Transfermarkt::Player.fetch_by_profile_uri(URI.encode(player_uri))
      end
    end

    puts "fetched club players for #{options[:name]}"

    self.new(options)
  end
end