Class: Sports::LeaguePeriod
- Inherits:
-
Object
- Object
- Sports::LeaguePeriod
- 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 Ö1 or such (what else?) allow space and dot - why? why not? e.g. HNL 1 NB I or NB II etc. %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
-
#alt_names ⇒ Object
Returns the value of attribute alt_names.
-
#end_season ⇒ Object
readonly
Returns the value of attribute end_season.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prev_name ⇒ Object
readonly
Returns the value of attribute prev_name.
-
#qname ⇒ Object
readonly
Returns the value of attribute qname.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#start_season ⇒ Object
readonly
Returns the value of attribute start_season.
Instance Method Summary collapse
- #codes ⇒ Object
-
#initialize(key:, name:, qname:, slug:, prev_name: nil, start_season: nil, end_season: nil) ⇒ LeaguePeriod
constructor
A new instance of LeaguePeriod.
- #names ⇒ Object
- #pretty_print(printer) ⇒ Object
Methods included from SportDb::NameHelper
#has_lang?, #has_year?, #normalize, #sanitize, #strip_lang, #strip_norm, #strip_year, #variants
Constructor Details
#initialize(key:, name:, qname:, slug:, prev_name: nil, start_season: nil, end_season: nil) ⇒ LeaguePeriod
Returns a new instance of LeaguePeriod.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sportdb/structs/league.rb', line 11 def initialize( key:, name:, qname:, slug:, prev_name: nil, start_season: nil, end_season: nil ) @key = key @name = name @qname = qname @slug = slug @prev_name = prev_name @start_season = start_season @end_season = end_season @alt_names = [] end |
Instance Attribute Details
#alt_names ⇒ Object
Returns the value of attribute alt_names.
9 10 11 |
# File 'lib/sportdb/structs/league.rb', line 9 def alt_names @alt_names end |
#end_season ⇒ Object (readonly)
Returns the value of attribute end_season.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def end_season @end_season end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def name @name end |
#prev_name ⇒ Object (readonly)
Returns the value of attribute prev_name.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def prev_name @prev_name end |
#qname ⇒ Object (readonly)
Returns the value of attribute qname.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def qname @qname end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def slug @slug end |
#start_season ⇒ Object (readonly)
Returns the value of attribute start_season.
6 7 8 |
# File 'lib/sportdb/structs/league.rb', line 6 def start_season @start_season end |
Instance Method Details
#codes ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sportdb/structs/league.rb', line 56 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 |
#names ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sportdb/structs/league.rb', line 81 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 |
#pretty_print(printer) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/sportdb/structs/league.rb', line 109 def pretty_print( printer ) buf = String.new buf << "<LeaguePeriod" buf << " #{@key}" buf << " (#{@start_season}-#{@end_season})" if @start_season || @end_season buf << " -" buf << " #{@name}" if @name != @qname buf << " | #{@qname}" else buf << "*" end buf << ">" printer.text( buf ) end |