Class: Sports::League

Inherits:
Object
  • Object
show all
Includes:
SportDb::NameHelper
Defined in:
lib/sportdb/structs/league.rb

Constant Summary collapse

IS_CODE_N_NAME_RE =

only allow asci a to z (why? why not?)

excludes 
%r{^
    [\p{Lu}0-9. ]+
$}x
IS_CODE_RE =

add space (or /) - why? why not?

%r{^
    [\p{Ll}0-9.]+
$}x

Constants included from SportDb::NameHelper

SportDb::NameHelper::LANG_RE, SportDb::NameHelper::NORM_RE, SportDb::NameHelper::YEAR_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SportDb::NameHelper

#has_lang?, #has_year?, #normalize, #sanitize, #strip_lang, #strip_norm, #strip_year, #variants

Constructor Details

#initialize(key:, name:, alt_names: [], country: nil, intl: false, clubs: true) ⇒ League

Returns a new instance of League.



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/sportdb/structs/league.rb', line 141

def initialize( key:, name:, alt_names: [],
                country: nil, intl: false, clubs: true )
  @key            = key
  @name           = name
  @alt_names      = alt_names

  @country        = country
  @intl           = intl
  @clubs          = clubs

  @periods        = []   ## change/rename to history - why? why not?

end

Instance Attribute Details

#alt_namesObject

Returns the value of attribute alt_names.



137
138
139
# File 'lib/sportdb/structs/league.rb', line 137

def alt_names
  @alt_names
end

#countryObject (readonly)

Returns the value of attribute country.



136
137
138
# File 'lib/sportdb/structs/league.rb', line 136

def country
  @country
end

#intlObject (readonly)

Returns the value of attribute intl.



136
137
138
# File 'lib/sportdb/structs/league.rb', line 136

def intl
  @intl
end

#keyObject (readonly)

Returns the value of attribute key.



136
137
138
# File 'lib/sportdb/structs/league.rb', line 136

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



136
137
138
# File 'lib/sportdb/structs/league.rb', line 136

def name
  @name
end

#periodsObject

Returns the value of attribute periods.



138
139
140
# File 'lib/sportdb/structs/league.rb', line 138

def periods
  @periods
end

Instance Method Details

#clubs?Boolean Also known as: club?

Returns:

  • (Boolean)


159
# File 'lib/sportdb/structs/league.rb', line 159

def clubs?()            @clubs == true; end

#codesObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/sportdb/structs/league.rb', line 191

def codes
     ## change/rename to more_codes - why? why?

     ##    get reference (tier/canonicial) codes via periods!!!!


     ## note - "auto-magically" downcase code (and code'n'name matches)!!

    ##  note - do NOT include key as code for now!!!

    ##

    ## todo/check - auto-remove space from code - why? why not?

    ##         e.g. NB I, NB II, HNL 1 => NBI, NBII, HBNL1, etc -

    codes = []
    alt_names.each do |name|
      if IS_CODE_N_NAME_RE.match?( name )
        codes << name.downcase
      elsif IS_CODE_RE.match?( name )
        codes << name
      else ## assume name

        ## do nothing - skip/ignore

      end
    end
    codes.uniq
end

#intl?Boolean

Returns:

  • (Boolean)


155
# File 'lib/sportdb/structs/league.rb', line 155

def intl?()      @intl == true; end

#namesObject



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/sportdb/structs/league.rb', line 216

def names
  names = [@name]
  alt_names.each do |name|
     if IS_CODE_N_NAME_RE.match?( name )
       names << name
     elsif IS_CODE_RE.match?( name )
       ## do nothing - skip/ignore

     else ## assume name

       names <<  strip_lang( name )
     end
 end

##  report duplicate names - why? why not

   ## check for duplicates - simple check for now - fix/improve

   ## todo/fix: (auto)remove duplicates - why? why not?

   count      = names.size
   count_uniq = names.uniq.size
   if count != count_uniq
     puts "** !!! ERROR !!! - #{count-count_uniq} duplicate name(s):"
     pp names
     pp self
     exit 1
   end

 names.uniq
end

#national?Boolean Also known as: domestic?

Returns:

  • (Boolean)


156
# File 'lib/sportdb/structs/league.rb', line 156

def national?()  @intl == false; end

#national_teams?Boolean Also known as: national_team?

Returns:

  • (Boolean)


160
# File 'lib/sportdb/structs/league.rb', line 160

def national_teams?()   @clubs == false; end

#pretty_print(printer) ⇒ Object

@alt_names=[],

@clubs=true,
@country=<Country: at - Austria (AUT)|


253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/sportdb/structs/league.rb', line 253

def pretty_print( printer )
  buf = String.new
  buf << "<League"
  buf << " INTL"   if @intl
  buf <<   if @clubs
               " CLUBS"
           else
               " NATIONAL TEAMS"
           end
  buf << ": #{@name}"

  if @alt_names && !@alt_names.empty?
    buf << "|"
    buf << @alt_names.join('|')
  end

  buf << ", #{@country.name} (#{@country.code})"     if @country

  if @periods && !@periods.empty?
    buf << ", "
    buf << @periods.map{|period| period.key }.uniq.join('|')
  end
  buf << ">"

  printer.text( buf )
end