class Sports::Team
todo/fix: remove self.create in structs!!! use just new!!!
Attributes
alt_names[RW]
todo: use just names for alt_names
- why? why not?
alt_names_auto[RW]
special import only attribs
code[RW]
todo: use just names for alt_names
- why? why not?
country[RW]
todo: use just names for alt_names
- why? why not?
key[RW]
todo: use just names for alt_names
- why? why not?
name[RW]
todo: use just names for alt_names
- why? why not?
wikipedia[RW]
year[RW]
todo: use just names for alt_names
- why? why not?
year_end[RW]
todo: use just names for alt_names
- why? why not?
Public Class Methods
new( **kwargs )
click to toggle source
# File lib/sportdb/structs/structs/team.rb, line 49 def initialize( **kwargs ) @alt_names = [] @alt_names_auto = [] update( kwargs ) unless kwargs.empty? end
Public Instance Methods
add_variants( name_or_names )
click to toggle source
# File lib/sportdb/structs/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()
click to toggle source
# File lib/sportdb/structs/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?()
click to toggle source
# File lib/sportdb/structs/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?()
click to toggle source
# File lib/sportdb/structs/structs/team.rb, line 32 def historic?() @year_end ? true : false; end
Also aliased as: past?
names()
click to toggle source
# File lib/sportdb/structs/structs/team.rb, line 15 def names ## todo/check: add alt_names_auto too? - why? why not? [@name] + @alt_names end
update( **kwargs )
click to toggle source
# File lib/sportdb/structs/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?()
click to toggle source
# File lib/sportdb/structs/structs/team.rb, line 35 def wikipedia?() @wikipedia; end
wikipedia_url()
click to toggle source
# File lib/sportdb/structs/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