Class: CatalogDb::Metal::NationalTeam
- Inherits:
-
Record
show all
- Defined in:
- lib/sportdb/catalogs/national_team.rb
Class Method Summary
collapse
Methods inherited from Record
_city, _league, _to_city, _to_country, _to_league, database, database=, database?
Methods inherited from BaseRecord
_country, _to_bool, columns, columns=, count, execute, tablename, tablename=
Class Method Details
._build_national_team(row) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sportdb/catalogs/national_team.rb', line 12
def self._build_national_team( row )
@cache ||= Hash.new
@cache[ row[0] ] ||= begin
team = Sports::NationalTeam.new(
key: row[0],
name: row[1],
code: row[2]
)
team.country = row[3] ? _to_country( row[3] ) : nil
team
end
end
|
.find(q) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/sportdb/catalogs/national_team.rb', line 32
def self.find( q )
q = normalize( unaccent(q.to_s) )
rows = execute( <<-SQL )
SELECT #{self.columns.join(', ')}
FROM national_teams
INNER JOIN national_team_names ON national_teams.key = national_team_names.key
WHERE national_team_names.name = '#{q}'
SQL
if rows.empty?
nil
else
_build_national_team( rows[0] )
end
end
|
.find!(q) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/sportdb/catalogs/national_team.rb', line 50
def self.find!( q )
team = find( q )
if team.nil?
puts "** !!! ERROR - no match for national team >#{q}< found"
exit 1
end
team
end
|