Class: Infostrada::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/infostrada/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Player

Returns a new instance of Player.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/infostrada/player.rb', line 18

def initialize(hash)
  @person_id   = hash['n_PersonID']
  @name = hash['c_Person']
  @short_name = hash['c_PersonShort']

  @birthdate = Formatter.format_date(hash['d_BirthDate'])

  # Function is one string like "Goalkeeper", "Defender", "Midfielder", "Forward", "Coach"...
  # Infostrada doesn't document the function strings so you should rely on function_type
  @function = hash['c_Function']
  @function_type = hash['n_FunctionType']
  @shirt_number = hash['n_ShirtNr']

  @contract_starts_at = Formatter.format_date(hash['d_ContractStartDate'])
  @contract_ends_at = Formatter.format_date(hash['d_ContractEndDate'])

  # Season statistics
  set_season_stats(hash)

  @nation = Nation.new(hash, 'person')

  self
end

Instance Attribute Details

#birthdateObject

Returns the value of attribute birthdate.



3
4
5
# File 'lib/infostrada/player.rb', line 3

def birthdate
  @birthdate
end

#contract_ends_atObject

Returns the value of attribute contract_ends_at.



4
5
6
# File 'lib/infostrada/player.rb', line 4

def contract_ends_at
  @contract_ends_at
end

#contract_starts_atObject

Returns the value of attribute contract_starts_at.



4
5
6
# File 'lib/infostrada/player.rb', line 4

def contract_starts_at
  @contract_starts_at
end

#functionObject

Returns the value of attribute function.



3
4
5
# File 'lib/infostrada/player.rb', line 3

def function
  @function
end

#function_typeObject

The function_type variable maps Infostradas n_FunctionType and can have one of these values:

1 = Keeper 2 = Defender 4 = Midfielder 8 = Forward 16 = Trainer 64 = Referee 128 = Linesman 1073741824 = 4th Official



16
17
18
# File 'lib/infostrada/player.rb', line 16

def function_type
  @function_type
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/infostrada/player.rb', line 3

def name
  @name
end

#nationObject

Returns the value of attribute nation.



4
5
6
# File 'lib/infostrada/player.rb', line 4

def nation
  @nation
end

#person_idObject

Returns the value of attribute person_id.



3
4
5
# File 'lib/infostrada/player.rb', line 3

def person_id
  @person_id
end

#season_statsObject

Returns the value of attribute season_stats.



4
5
6
# File 'lib/infostrada/player.rb', line 4

def season_stats
  @season_stats
end

#shirt_numberObject

Returns the value of attribute shirt_number.



3
4
5
# File 'lib/infostrada/player.rb', line 3

def shirt_number
  @shirt_number
end

#short_nameObject

Returns the value of attribute short_name.



3
4
5
# File 'lib/infostrada/player.rb', line 3

def short_name
  @short_name
end

Instance Method Details

#name?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/infostrada/player.rb', line 42

def name?
  @name && !@name.empty?
end