Class: Transfermarkt::Player
- Inherits:
-
EntityBase
- Object
- EntityBase
- Transfermarkt::Player
- Defined in:
- lib/transfermarkt/player.rb
Instance Attribute Summary collapse
-
#age ⇒ Object
Returns the value of attribute age.
-
#club ⇒ Object
Returns the value of attribute club.
-
#complete_name ⇒ Object
Returns the value of attribute complete_name.
-
#date_of_birth ⇒ Object
Returns the value of attribute date_of_birth.
-
#foot ⇒ Object
Returns the value of attribute foot.
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#height ⇒ Object
Returns the value of attribute height.
-
#injuries_data ⇒ Object
Returns the value of attribute injuries_data.
-
#market_value ⇒ Object
Returns the value of attribute market_value.
-
#name_in_native_country ⇒ Object
Returns the value of attribute name_in_native_country.
-
#nationality ⇒ Object
Returns the value of attribute nationality.
-
#performance_data ⇒ Object
Returns the value of attribute performance_data.
-
#picture ⇒ Object
Returns the value of attribute picture.
-
#player_agent ⇒ Object
Returns the value of attribute player_agent.
-
#position ⇒ Object
Returns the value of attribute position.
-
#profile_uri ⇒ Object
Returns the value of attribute profile_uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Player
constructor
A new instance of Player.
- #valid_player? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Player
Returns a new instance of Player.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/transfermarkt/player.rb', line 20 def initialize( = {}) super = { :invalid => :replace, # Replace invalid byte sequences :undef => :replace, # Replace anything not defined in ASCII :replace => '', # Use a blank for those replacements :UNIVERSAL_NEWLINE_DECORATOR => true # Always break lines with \n } self.age = self.age.to_i self.market_value = #self.market_value.to_s.gsub(",", "").to_i self.height = self.height.to_s.gsub(",", "").to_i self.nationality = self.nationality.to_s.encode(Encoding.find('ASCII'), ).split("\n").collect(&:strip) if self.date_of_birth.present? self.age = Date.today.year - Date.parse(self.date_of_birth).year end end |
Instance Attribute Details
#age ⇒ Object
Returns the value of attribute age.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def age @age end |
#club ⇒ Object
Returns the value of attribute club.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def club @club end |
#complete_name ⇒ Object
Returns the value of attribute complete_name.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def complete_name @complete_name end |
#date_of_birth ⇒ Object
Returns the value of attribute date_of_birth.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def date_of_birth @date_of_birth end |
#foot ⇒ Object
Returns the value of attribute foot.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def foot @foot end |
#full_name ⇒ Object
Returns the value of attribute full_name.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def full_name @full_name end |
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def height @height end |
#injuries_data ⇒ Object
Returns the value of attribute injuries_data.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def injuries_data @injuries_data end |
#market_value ⇒ Object
Returns the value of attribute market_value.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def market_value @market_value end |
#name_in_native_country ⇒ Object
Returns the value of attribute name_in_native_country.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def name_in_native_country @name_in_native_country end |
#nationality ⇒ Object
Returns the value of attribute nationality.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def nationality @nationality end |
#performance_data ⇒ Object
Returns the value of attribute performance_data.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def performance_data @performance_data end |
#picture ⇒ Object
Returns the value of attribute picture.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def picture @picture end |
#player_agent ⇒ Object
Returns the value of attribute player_agent.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def player_agent @player_agent end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def position @position end |
#profile_uri ⇒ Object
Returns the value of attribute profile_uri.
3 4 5 |
# File 'lib/transfermarkt/player.rb', line 3 def profile_uri @profile_uri end |
Class Method Details
.fetch_by_profile_uri(profile_uri = "") ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/transfermarkt/player.rb', line 59 def self.fetch_by_profile_uri(profile_uri = "") req = self.get("/#{profile_uri}", headers: {"User-Agent" => UserAgents.rand()}) if req.code != 200 nil else #byebug profile_html = Nokogiri::HTML(req.parsed_response) = {} puts "**** Parsing player #{profile_uri}" [:profile_uri] = profile_uri # //*[@id="main"]/div[7]/div/div/div[2]/div[2]/div[2]/table/tbody/tr[2]/td/a club = profile_html.css(".hauptpunkt > a:nth-child(1)").text unless club.empty? [:club] = profile_html.css(".hauptpunkt > a:nth-child(1)").text # options[:position] = profile_html.xpath('//*[@id="main"]//div[7]//table[1]//tr[3]//td[1]')[1].text.strip [:full_name] = profile_html.css(".dataName > h1:nth-child(2)").text [:picture] = "https:" + profile_html.css(".dataBild > img:nth-child(1)").first["src"] #profile_html.xpath('//*[@id="main"]//div[7]//div//div//div[2]//div[1]//img')[0]["src"] # options[:name_in_native_country] = profile_html.xpath('//*[@id="main"]//div[9]//div[1]//div[2]//div[2]//div[1]//div//table//tr[1]//td[1]')[0].text [:market_value] = profile_html.css(".dataMarktwert > a:nth-child(1)").text.split(" ").first agent = profile_html.css("div.dataDaten:nth-child(2) > p:nth-child(4) > span:nth-child(2) > a:nth-child(1)").text # if options[:market_value].include?("Mil") # options[:market_value] = options[:market_value].to_f * 1_000_000 # else # options[:market_value] = options[:market_value].to_f * 100_000 # end [:name_in_native_country] = [:full_name] [:complete_name] = [:full_name] player_info = profile_html.css("table.auflistung").search("tr") player_info.each do |info_row| header = info_row.search('th')[0].text.strip if header == "Name in home country:" [:name_in_native_country] = info_row.search('td')[0].text.strip puts elsif header == "Date of birth:" [:date_of_birth] = info_row.search('td')[0].text.strip puts elsif header == "Place of birth:" [:place_of_birth] = info_row.search('td')[0].text.strip puts # elsif header == "Age:" # options[:age] = info_row.search('td')[0].text.strip # puts options elsif header == "Height:" [:height] = info_row.search('td')[0].text.strip puts elsif header == "Nationality:" [:nationality] = info_row.search('td')[0].text.strip puts elsif header == "Position:" [:position] = info_row.search('td')[0].text.strip puts elsif header == "Foot:" [:foot] = info_row.search('td')[0].text.strip puts elsif header == "Complete name:" [:complete_name] = info_row.search('td')[0].text.strip puts end end # get player performance # options[:performance_data] = {} # # performance_uri = profile_uri.gsub("profil", "leistungsdaten") + "/saison/" # # years = (Time.now.year - 6..Time.now.year).to_a # years.each do |year| # goalkeeper = options[:position] == "Goalkeeper" # options[:performance_data][year.to_s] = self.fetch_performance_data(performance_uri + year.to_s, goalkeeper) # end # # # Get injury data # # injury_uri = profile_uri.gsub("profil", "verletzungen") # # options[:injuries_data] = self.fetch_injuries_data(injury_uri) end self.new() end end |
.search(player_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/transfermarkt/player.rb', line 46 def self.search(player_name) req = self.get("/schnellsuche/ergebnis/schnellsuche", query: {query: player_name, x: 0, y:0}) if req.code != 200 nil else profile_html = Nokogiri::HTML(req.parsed_response) results = {} link = profile_html.css(".spielprofil_tooltip")[0]["href"] self.fetch_by_profile_uri(link) end end |
Instance Method Details
#valid_player? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/transfermarkt/player.rb', line 38 def valid_player? if club.nil? or club.empty? false else true end end |