Class: Sports::LeaguePeriod

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/search/sport-leagues.rb

Class Method Summary collapse

Class Method Details

._searchObject



13
# File 'lib/sportdb/search/sport-leagues.rb', line 13

def self._search() CatalogDb::Metal::LeaguePeriod; end

.find(q, season:) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sportdb/search/sport-leagues.rb', line 83

def self.find( q, season: )
  period = nil
  recs = match( q, season: season )
  # pp m

  if recs.empty?
    ## fall through/do nothing
  elsif recs.size > 1
    puts "** !!! ERROR - too many matches (#{recs.size}) for league period >#{q}+#{season}<:"
    pp recs
    exit 1
  else
    period = recs[0]
  end

  period
end

.find!(q, season:) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/sportdb/search/sport-leagues.rb', line 101

def self.find!( q, season: )
  period = find( q, season: season )
  if period.nil?
    puts "** !!! ERROR - no league period found for >#{q}+#{season}<, add to leagues table; sorry"
    exit 1
  end
  period
end

.find_by(name: nil, code: nil, season:) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/sportdb/search/sport-leagues.rb', line 72

def self.find_by( name: nil, code: nil, season: )
  if code && name.nil?
    find_by_code( code, season: season )
  elsif name && code.nil?
    find_by_name( name, season: season )
  else
    raise ArgumentError, "LeaguePeriod.find_by - one (and only one arg) required - code: or name:"
  end
end

.find_by_code(code, season:) ⇒ Object

more deriv support functions / helpers



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sportdb/search/sport-leagues.rb', line 36

def self.find_by_code( code, season: )
  period = nil
  recs  = _search.match_by_code( code, season: season )
  # pp m

  if recs.empty?
    ## fall through/do nothing
  elsif recs.size > 1
    puts "** !!! ERROR - too many (code) matches (#{recs.size}) for league period >#{code}+#{season}<:"
    pp recs
    exit 1
  else
    period = recs[0]
  end

  period
end

.find_by_name(name, season:) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sportdb/search/sport-leagues.rb', line 54

def self.find_by_name( name, season: )
  period = nil
  recs  = _search.match_by_name( name, season: season )
  # pp m

  if recs.empty?
    ## fall through/do nothing
  elsif recs.size > 1
    puts "** !!! ERROR - too many (name) matches (#{recs.size}) for league period >#{name}+#{season}<:"
    pp recs
    exit 1
  else
    period = recs[0]
  end

  period
end

.match(q, season:) ⇒ Object

all-in-one query (name or code)



29
30
31
# File 'lib/sportdb/search/sport-leagues.rb', line 29

def self.match( q, season: )
   _search.match_by_name_or_code( q, season: season )
end

.match_by(name: nil, code: nil, season:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sportdb/search/sport-leagues.rb', line 16

def self.match_by( name: nil, code: nil, season: )
  ## todo/fix upstream - remove "generic" match_by() - why? why not?
  ###
  if code && name.nil?
   _search.match_by_code( code, season: season )
 elsif name && code.nil?
   _search.match_by_name( name, season: season )
 else
   raise ArgumentError, "LeaguePeriod.match_by - one (and only one arg) required - code: or name:"
 end
end