Class: CatalogDb::Metal::BaseRecord

Inherits:
Object
  • Object
show all
Extended by:
SportDb::NameHelper
Defined in:
lib/sportdb/catalogs/base.rb

Overview

or just use Base or such - why? why not?

Direct Known Subclasses

PlayerRecord, Record

Class Method Summary collapse

Class Method Details

._country(country) ⇒ Object

todo/check - make _country available to all dbs/records? why? why not?



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sportdb/catalogs/base.rb', line 57

def self._country( country )
   if country.is_a?( String ) || country.is_a?( Symbol )
     # note: query/find country via catalog db
     rec = Country.find_by_code( country )
     rec = Country.find_by_name( country )  if rec.nil?
     if rec.nil?
       puts "** !!! ERROR !!! - unknown country >#{country}< - no match found, sorry - add to world/countries.txt in config"
       exit 1
     end
     rec
   else
     country  ## (re)use country struct - no need to run lookup again
   end
end

._to_bool(value) ⇒ Object

incl. strip_year( name )

has_year?( name)
strip_lang( name )
normalize( name )


42
43
44
45
46
47
48
49
50
51
# File 'lib/sportdb/catalogs/base.rb', line 42

def self._to_bool( value )
  if value == 0
    false
  elsif value == 1
    true
  else
    ## use TypeError - why? why not? or if exits ValueError?
    raise ArgumentError, "0 or 1 expected for bool in sqlite; got #{value}"
  end
end

.columnsObject



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

def self.columns() @columns; end

.columns=(names) ⇒ Object



21
22
23
24
25
# File 'lib/sportdb/catalogs/base.rb', line 21

def self.columns=(names)
   ## note: auto-add table name to qualify
   @columns = names.map {|name| "#{self.tablename}.#{name}" }
   @columns
end

.countObject



28
29
30
31
32
# File 'lib/sportdb/catalogs/base.rb', line 28

def self.count
   sql = "SELECT count(*) FROM #{self.tablename}"
   rows = execute( sql )
   rows[0][0]    # e.g. returns [[241]]
end

.execute(sql) ⇒ Object



12
13
14
15
16
# File 'lib/sportdb/catalogs/base.rb', line 12

def self.execute( sql )
   ## puts "==> sql query [#{self.name}]"
   ## puts sql
   database.execute( sql )
end

.tablenameObject



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

def self.tablename() @tablename; end

.tablename=(name) ⇒ Object



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

def self.tablename=(name) @tablename = name; end