module SportDb::NameHelper

Constants

LANG_RE
NORM_RE

note: also add (),’,− etc. e.g.

 Estudiantes (LP) => Estudiantes LP
 Saint Patrick’s Athletic FC => Saint Patricks Athletic FC
 Myllykosken Pallo −47 => Myllykosken Pallo 47

add & too!!
 e.g. Brighton & Hove Albion => Brighton Hove Albion  -- and others in England
YEAR_RE

note: allow placeholder years to e.g. (-_) or (-????)

  for marking missing (to be filled in) years
e.g. (1887-1911), (-2013),
    (1946-2001, 2013-) etc.
todo/check: make more strict  e.g. only accept 4-digit years? - why? why not?

Public Instance Methods

has_lang?( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 32
def has_lang?( name ) name =~ LANG_RE; end
has_year?( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 22
def has_year?( name ) name =~ YEAR_RE; end
normalize( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 72
def normalize( name )
  # note: do NOT call sanitize here (keep normalize "atomic" for reuse)
  name = strip_norm( name )
  name = name.gsub( ' ', '' )  # note: also remove all spaces!!!

  ## todo/check: use our own downcase - why? why not?
  name = downcase_i18n( name )     ## do NOT care about upper and lowercase for now
  name
end
sanitize( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 35
def sanitize( name )
  ## check for year(s) e.g. (1887-1911), (-2013),
  ##                        (1946-2001,2013-) etc.
  name = strip_year( name )
  ## check lang codes e.g. [en], [fr], etc.
  name = strip_lang( name )
  name
end
strip_lang( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 28
def strip_lang( name )
   name.gsub( LANG_RE, '' ).strip
end
strip_norm( name ) click to toggle source

for norm(alizing) names

# File lib/sportdb/structs/name_helper.rb, line 68
def strip_norm( name )
  name.gsub( NORM_RE, '' )
end
strip_year( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 15
def strip_year( name )
  ## check for year(s) e.g. (1887-1911), (-2013),
  ##                        (1946-2001, 2013-) etc.
  ##  todo/check: only sub once (not global) - why? why not?
  name.gsub( YEAR_RE, '' ).strip
end
variants( name ) click to toggle source
# File lib/sportdb/structs/name_helper.rb, line 83
def variants( name )  Variant.find( name ); end