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
36
37
# File 'lib/transfermarkt/club.rb', line 9

def self.fetch_by_club_uri(club_uri, fetch_players = false)
  puts "fetching club #{club_uri}"

  req = self.get("/#{club_uri}", headers: {"User-Agent" => Transfermarkt::USER_AGENT})
  if req.code != 200
    nil
  else
    club_html = Nokogiri::HTML(req.parsed_response)
    options = {}

    options[:club_uri] = club_uri
    options[:name] = club_html.xpath('//*[@id="vereinsinfo"]').text
    options[:country] = club_html.xpath('//*[@id="centerbig"]//form//table//tr[1]//td[2]//h1//a[2]').text
    options[:player_uris] = club_html.xpath('//table[@id="spieler"]//tr//td//table//tr//td[2]//a[contains(@href,"profil")]').collect{|player_html| player_html["href"]}

    puts "found #{options[:player_uris].count} players"
    options[:players] = []

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

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

    self.new(options)
  end
end