Class: Sports::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/structs/team.rb

Overview

shared base for clubs AND natinal_teams

Direct Known Subclasses

Club, NationalTeam

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Team

Returns a new instance of Team.



65
66
67
68
69
# File 'lib/sportdb/structs/team.rb', line 65

def initialize( **kwargs )
  @alt_names      = []
 
  update( **kwargs )  unless kwargs.empty?
end

Instance Attribute Details

#alt_namesObject

todo: use just names for alt_names - why? why not?



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def alt_names
  @alt_names
end

#codeObject

todo: use just names for alt_names - why? why not?



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def code
  @code
end

#countryObject

todo: use just names for alt_names - why? why not?



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def country
  @country
end

#keyObject

all names



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def key
  @key
end

#nameObject

todo: use just names for alt_names - why? why not?



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def name
  @name
end

#wikipediaObject

special import only attribs



44
45
46
# File 'lib/sportdb/structs/team.rb', line 44

def wikipedia
  @wikipedia
end

#yearObject

todo: use just names for alt_names - why? why not?



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def year
  @year
end

#year_endObject

todo: use just names for alt_names - why? why not?



7
8
9
# File 'lib/sportdb/structs/team.rb', line 7

def year_end
  @year_end
end

Instance Method Details

#historic?Boolean Also known as: past?

Returns:

  • (Boolean)


47
# File 'lib/sportdb/structs/team.rb', line 47

def historic?()  @year_end ? true : false; end

#namesObject



13
14
15
16
# File 'lib/sportdb/structs/team.rb', line 13

def names
  ## todo/check: add alt_names_auto too? - why? why not?
  [@name] + @alt_names
end

#update(**kwargs) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/sportdb/structs/team.rb', line 71

def update( **kwargs )
  @key         = kwargs[:key]        if kwargs.has_key?( :key )
  @name        = kwargs[:name]       if kwargs.has_key?( :name )
  @code        = kwargs[:code]       if kwargs.has_key?( :code )
  @alt_names   = kwargs[:alt_names]  if kwargs.has_key?( :alt_names )
  self   ## note - MUST return self for chaining
end

#wikipedia?Boolean

Returns:

  • (Boolean)


51
# File 'lib/sportdb/structs/team.rb', line 51

def wikipedia?()  @wikipedia; end

#wikipedia_urlObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sportdb/structs/team.rb', line 52

def wikipedia_url
  if @wikipedia
    ##  note: replace spaces with underscore (-)
    ##  e.g. Club Brugge KV => Club_Brugge_KV
    ##  todo/check/fix:
    ##    check if "plain" dash (-) needs to get replaced with typographic dash??
    "https://en.wikipedia.org/wiki/#{@wikipedia.gsub(' ','_')}"
  else
    nil
  end
end