Class: Sports::Team
- Inherits:
-
Object
- Object
- Sports::Team
- Includes:
- SportDb::NameHelper
- Defined in:
- lib/sports/structs/team.rb
Overview
todo/fix: remove self.create in structs!!! use just new!!!
Direct Known Subclasses
Constant Summary
Constants included from SportDb::NameHelper
SportDb::NameHelper::LANG_RE, SportDb::NameHelper::NORM_RE, SportDb::NameHelper::YEAR_RE
Instance Attribute Summary collapse
-
#alt_names ⇒ Object
todo: use just names for alt_names - why? why not?.
-
#alt_names_auto ⇒ Object
special import only attribs.
-
#code ⇒ Object
todo: use just names for alt_names - why? why not?.
-
#country ⇒ Object
todo: use just names for alt_names - why? why not?.
-
#key ⇒ Object
all names.
-
#name ⇒ Object
todo: use just names for alt_names - why? why not?.
-
#wikipedia ⇒ Object
wikipedia page name (for english (en)).
-
#year ⇒ Object
todo: use just names for alt_names - why? why not?.
-
#year_end ⇒ Object
todo: use just names for alt_names - why? why not?.
Instance Method Summary collapse
- #add_variants(name_or_names) ⇒ Object
- #duplicates ⇒ Object
- #duplicates? ⇒ Boolean
- #historic? ⇒ Boolean (also: #past?)
-
#initialize(**kwargs) ⇒ Team
constructor
A new instance of Team.
- #names ⇒ Object
- #update(**kwargs) ⇒ Object
- #wikipedia? ⇒ Boolean
- #wikipedia_url ⇒ Object
Methods included from SportDb::NameHelper
#has_lang?, #has_year?, #normalize, #sanitize, #strip_lang, #strip_norm, #strip_year, #variants
Constructor Details
#initialize(**kwargs) ⇒ Team
Returns a new instance of Team.
49 50 51 52 53 54 |
# File 'lib/sports/structs/team.rb', line 49 def initialize( **kwargs ) @alt_names = [] @alt_names_auto = [] update( kwargs ) unless kwargs.empty? end |
Instance Attribute Details
#alt_names ⇒ Object
todo: use just names for alt_names - why? why not?
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def alt_names @alt_names end |
#alt_names_auto ⇒ Object
special import only attribs
28 29 30 |
# File 'lib/sports/structs/team.rb', line 28 def alt_names_auto @alt_names_auto end |
#code ⇒ Object
todo: use just names for alt_names - why? why not?
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def code @code end |
#country ⇒ Object
todo: use just names for alt_names - why? why not?
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def country @country end |
#key ⇒ Object
all names
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def key @key end |
#name ⇒ Object
todo: use just names for alt_names - why? why not?
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def name @name end |
#wikipedia ⇒ Object
wikipedia page name (for english (en))
29 30 31 |
# File 'lib/sports/structs/team.rb', line 29 def wikipedia @wikipedia end |
#year ⇒ Object
todo: use just names for alt_names - why? why not?
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def year @year end |
#year_end ⇒ Object
todo: use just names for alt_names - why? why not?
9 10 11 |
# File 'lib/sports/structs/team.rb', line 9 def year_end @year_end end |
Instance Method Details
#add_variants(name_or_names) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/sports/structs/team.rb', line 90 def add_variants( name_or_names ) names = name_or_names.is_a?(Array) ? name_or_names : [name_or_names] names.each do |name| name = sanitize( name ) self.alt_names_auto += variants( name ) end end |
#duplicates ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sports/structs/team.rb', line 78 def duplicates names = [name] + alt_names + alt_names_auto ## calculate (count) frequency and select if greater than one names.reduce( {} ) do |h,name| norm = normalize( sanitize(name) ) h[norm] ||= [] h[norm] << name; h end.select { |norm,names| names.size > 1 } end |
#duplicates? ⇒ Boolean
71 72 73 74 75 76 |
# File 'lib/sports/structs/team.rb', line 71 def duplicates? names = [name] + alt_names + alt_names_auto names = names.map { |name| normalize( sanitize(name) ) } names.size != names.uniq.size end |
#historic? ⇒ Boolean Also known as: past?
32 |
# File 'lib/sports/structs/team.rb', line 32 def historic?() @year_end ? true : false; end |
#names ⇒ Object
15 16 17 18 |
# File 'lib/sports/structs/team.rb', line 15 def names ## todo/check: add alt_names_auto too? - why? why not? [@name] + @alt_names end |
#update(**kwargs) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/sports/structs/team.rb', line 56 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
35 |
# File 'lib/sports/structs/team.rb', line 35 def wikipedia?() @wikipedia; end |
#wikipedia_url ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sports/structs/team.rb', line 36 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 |