Class: CatalogDb::Metal::Record

Inherits:
BaseRecord show all
Defined in:
lib/sportdb/catalogs/base.rb

Overview

todo (fix) / rename to CatalogRecord - why? why not?

Direct Known Subclasses

City, Club, Country, EventInfo, Ground, League, LeaguePeriod, NationalTeam

Class Method Summary collapse

Methods inherited from BaseRecord

_country, _to_bool, columns, columns=, count, execute, tablename, tablename=

Class Method Details

._city(city) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/sportdb/catalogs/base.rb', line 141

def self._city( city )
   if city.is_a?( String ) || city.is_a?( Symbol )
     # note: query/find country via catalog db
     recs = City.match_by( name: city )
     if recs.empty?
       puts "** !!! ERROR !!! - unknown city >#{city}< - no match found, sorry"
       exit 1
     elsif recs.size > 1
       puts "** !!! ERROR !!! - city >#{city}< - too many matches found (#{recs.size}), sorry"
       pp recs
       exit 1
     end
     recs[0]
   else
     city  ## (re)use city struct - no need to run lookup again
   end
end

._league(league) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/sportdb/catalogs/base.rb', line 160

def self._league( league )
   if league.is_a?( String ) || league.is_a?( Symbol )
     # note: query/find country via catalog db
     ##   only query by code - why? why not?
     recs = League.match_by_name_or_code( league )
     if recs.empty?
       puts "** !!! ERROR !!! - unknown league >#{league}< - no match found, sorry"
       exit 1
     elsif recs.size > 1
       puts "** !!! ERROR !!! - league >#{league}< - too many matches found (#{recs.size}), sorry"
       pp recs
       exit 1
     end
     recs[0]
   else   ## assume league struct
     league  ## (re)use league struct - no need to run lookup again
   end
end

._to_city(key) ⇒ Object

rename; use find_by_key / find_by( key: )



135
136
137
138
# File 'lib/sportdb/catalogs/base.rb', line 135

def self._to_city( key )   ### rename; use find_by_key / find_by( key: )
   # note: use cached record or (faster) key lookup on fallback
   City._record( key )
end

._to_country(key) ⇒ Object



130
131
132
133
# File 'lib/sportdb/catalogs/base.rb', line 130

def self._to_country( key )
   # note: use cached record or (faster) key lookup on fallback
   Country._record( key )
end

._to_league(key) ⇒ Object

share common methods for reuse



126
127
128
# File 'lib/sportdb/catalogs/base.rb', line 126

def self._to_league( key )
   League._record( key )
end

.databaseObject



106
107
108
109
110
111
112
113
114
# File 'lib/sportdb/catalogs/base.rb', line 106

def self.database
   ### note: only one database for all derived records/tables!!!
   ##   thus MUST use @@ and not @!!!!!
   ##
   ##  default to built-in via footballdb-data gem for now!!!
   @@db ||= SQLite3::Database.new( "#{FootballDb::Data.data_dir}/catalog.db",
                                   readonly: true )
   @@db
end

.database=(path) ⇒ Object



116
117
118
119
120
121
# File 'lib/sportdb/catalogs/base.rb', line 116

def self.database=(path)
   puts "==> setting (internal) catalog db to: >#{path}<"
   @@db = SQLite3::Database.new( path, readonly: true )
   pp @@db
   @@db
end

.database?Boolean

lets you query if datbase setup

Returns:

  • (Boolean)


104
# File 'lib/sportdb/catalogs/base.rb', line 104

def self.database?() defined?( @@db ); end