sportdb 1.8.5 → 1.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -128,6 +128,25 @@ EXAMPLES
128
128
  ~~~
129
129
 
130
130
 
131
+ ## Usage in Ruby (Console / Interactive Shell)
132
+
133
+
134
+ Try the built-in console script. In your interactive Ruby shell type:
135
+
136
+ >> require 'sportdb/console'
137
+ # => Welcome to sport.db, version 1.9.7 (world.db, version 1.9.3)!
138
+
139
+ This will try to connect to the `sport.db` SQLite database in your working folder.
140
+ To get started try some queries, for example:
141
+
142
+ >> Team.count
143
+ # => 157
144
+ >> t = Team.find_by_key( 'barcelona' )
145
+ # => ...
146
+
147
+ and so on.
148
+
149
+
131
150
 
132
151
  ## Install
133
152
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'sportdb'
4
- SportDb.main
4
+
5
+ SportDb.main
@@ -266,9 +266,10 @@ desc 'Show stats'
266
266
  command :stats do |c|
267
267
  c.action do |g,o,args|
268
268
 
269
- connect_to_db( opts )
269
+ connect_to_db( opts )
270
270
 
271
271
  SportDb.tables
272
+ WorldDb.tables
272
273
 
273
274
  puts 'Done.'
274
275
  end
@@ -17,30 +17,31 @@ require 'yaml'
17
17
  ##
18
18
  ## todo/fix: just use include SportDb::Models - why? why not? is it possible/working?
19
19
 
20
- Badge = SportDb::Models::Badge
21
- Event = SportDb::Models::Event
22
- Game = SportDb::Models::Game
23
- Goal = SportDb::Models::Goal
24
- Group = SportDb::Models::Group
25
- League = SportDb::Models::League
26
- Person = SportDb::Models::Person
27
- Race = SportDb::Models::Race
28
- Record = SportDb::Models::Record
29
- Roster = SportDb::Models::Roster
30
- Round = SportDb::Models::Round
31
- Run = SportDb::Models::Run
32
- Season = SportDb::Models::Season
33
- Team = SportDb::Models::Team
34
- Track = SportDb::Models::Track
35
-
36
-
37
- Tag = WorldDb::Models::Tag
38
- Tagging = WorldDb::Models::Tagging
39
- Continent = WorldDb::Models::Continent
40
- Country = WorldDb::Models::Country
41
- Region = WorldDb::Models::Region
42
- City = WorldDb::Models::City
43
- Prop = WorldDb::Models::Prop
20
+ Badge = SportDb::Model::Badge
21
+ Event = SportDb::Model::Event
22
+ Game = SportDb::Model::Game
23
+ Goal = SportDb::Model::Goal
24
+ Group = SportDb::Model::Group
25
+ League = SportDb::Model::League
26
+ Person = SportDb::Model::Person
27
+ Race = SportDb::Model::Race
28
+ Record = SportDb::Model::Record
29
+ Roster = SportDb::Model::Roster
30
+ Round = SportDb::Model::Round
31
+ Run = SportDb::Model::Run
32
+ Season = SportDb::Model::Season
33
+ Team = SportDb::Model::Team
34
+ Track = SportDb::Model::Track
35
+
36
+
37
+ Tag = WorldDb::Model::Tag
38
+ Tagging = WorldDb::Model::Tagging
39
+ Continent = WorldDb::Model::Continent
40
+ Country = WorldDb::Model::Country
41
+ Region = WorldDb::Model::Region
42
+ City = WorldDb::Model::City
43
+ Prop = WorldDb::Model::Prop
44
+
44
45
 
45
46
  ## connect to db
46
47
 
@@ -56,9 +57,17 @@ ActiveRecord::Base.establish_connection( DB_CONFIG )
56
57
 
57
58
  puts "Welcome to sport.db, version #{SportDb::VERSION} (world.db, version #{WorldDb::VERSION})!"
58
59
 
60
+ ## print tables stats (e.g. no of records)
61
+ puts 'sport.db'
62
+ puts '--------'
59
63
  SportDb.tables
60
64
 
61
- puts "Ready."
65
+ puts 'world.db'
66
+ puts '--------'
67
+ WorldDb.tables
68
+
69
+ puts 'Ready.'
70
+
62
71
 
63
72
  ## add some predefined shortcuts
64
73
 
@@ -1,34 +1,42 @@
1
1
  # encoding: utf-8
2
2
 
3
+
3
4
  ### todo/fix: move to sportdb-data gem/plugin/addon ??
5
+ ### fix: rename to ::Key (singular) - why? why not??
4
6
 
5
7
 
6
- ### fix: rename to ::Key (singular) - why? why not??
8
+ module SportDb
9
+
10
+ module EventKeys
11
+ # use constants for known keys; lets us define aliases (if things change)
12
+ AT_2011_12 = 'at.2011/12'
13
+ AT_2012_13 = 'at.2012/13'
14
+ AT_2013_14 = 'at.2013/14'
15
+
16
+ AT_CUP_2012_13 = 'at.cup.2012/13'
17
+ AT_CUP_2013_14 = 'at.cup.2013/14'
18
+
19
+ CL_2012_13 = 'cl.2012/13'
20
+ CL_2013_14 = 'cl.2013/14'
21
+
22
+ EURO_2008 = 'euro.2008'
23
+ EURO_2012 = 'euro.2012'
24
+
25
+ WORLD_2010 = 'world.2010'
26
+ WORLD_2014 = 'world.2014'
27
+
28
+ WORLD_QUALI_EUROPE_2014 = 'world.quali.europe.2014'
29
+ WORLD_QUALI_AMERICA_2014 = 'world.quali.america.2014'
30
+
31
+ ##################################################################
32
+ # NB: see github/openfootball (leagues.txt) for keys in use
33
+ end # module EventKeys
34
+
35
+
36
+
37
+ module Keys
38
+ ## all keys - used by anybody? really needed? check back later
39
+ include EventKeys
40
+ end
7
41
 
8
- module SportDb::Keys
9
-
10
- module EventKeys
11
- # use constants for known keys; lets us define aliases (if things change)
12
-
13
-
14
- AT_2011_12 = 'at.2011/12'
15
- AT_2012_13 = 'at.2012/13'
16
- AT_CUP_2012_13 = 'at.cup.2012/13'
17
-
18
- CL_2012_13 = 'cl.2012/13'
19
-
20
- EURO_2008 = 'euro.2008'
21
- EURO_2012 = 'euro.2012'
22
-
23
- WORLD_2010 = 'world.2010'
24
-
25
- WORLD_QUALI_EUROPE_2014 = 'world.quali.europe.2014'
26
- WORLD_QUALI_AMERICA_2014 = 'world.quali.america.2014'
27
-
28
- ############################
29
- ## NB: see db/leagues.rb for keys in use
30
- end
31
-
32
- include SportDb::Keys::EventKeys
33
-
34
- end # module SportDb::Keys
42
+ end # module SportDb
@@ -1,43 +1,35 @@
1
1
  # encoding: utf-8
2
2
 
3
- module SportDb::Model
4
-
5
- ## add convenience finders to some model classes
6
-
7
- class Event
8
-
9
- include SportDb::Keys::EventKeys
10
-
11
- def self.find_at_2012_13!
12
- self.find_by_key!( AT_2012_13 )
13
- end
14
-
15
- def self.find_at_cup_2012_13!
16
- self.find_by_key!( AT_CUP_2012_13 )
17
- end
18
-
19
- def self.find_cl_2012_13!
20
- self.find_by_key!( CL_2012_13 )
21
- end
22
-
23
- def self.find_euro_2012!
24
- self.find_by_key!( EURO_2012 )
25
- end
26
-
27
- def self.find_world_2010!
28
- self.find_by_key!( WORLD_2010 )
29
- end
30
-
31
- def self.find_world_quali_europe_2014!
32
- self.find_by_key!( WORLD_QUALI_EUROPE_2014 )
33
- end
34
-
35
- def self.find_world_quali_america_2014!
36
- self.find_by_key!( WORLD_QUALI_AMERICA_2014 )
37
- end
38
-
39
- end # class Event
40
-
41
- end # module SportDb::Model
3
+ module SportDb
4
+ module Model
42
5
 
43
6
 
7
+ ## add convenience finders to some model classes
8
+
9
+ class Event
10
+
11
+ include SportDb::EventKeys
12
+
13
+ def self.find_at_2012_13!() self.find_by_key!( AT_2012_13 ) end
14
+ def self.find_at_2013_14!() self.find_by_key!( AT_2013_14 ) end
15
+
16
+ def self.find_at_cup_2012_13!() self.find_by_key!( AT_CUP_2012_13 ) end
17
+ def self.find_at_cup_2013_14!() self.find_by_key!( AT_CUP_2013_14 ) end
18
+
19
+ def self.find_cl_2012_13!() self.find_by_key!( CL_2012_13 ) end
20
+ def self.find_cl_2013_14!() self.find_by_key!( CL_2013_14 ) end
21
+
22
+ def self.find_euro_2008!() self.find_by_key!( EURO_2008 ) end
23
+ def self.find_euro_2012!() self.find_by_key!( EURO_2012 ) end
24
+
25
+ def self.find_world_2010!() self.find_by_key!( WORLD_2010 ) end
26
+ def self.find_world_2014!() self.find_by_key!( WORLD_2014 ) end
27
+
28
+ def self.find_world_quali_europe_2014!() self.find_by_key!( WORLD_QUALI_EUROPE_2014 ) end
29
+ def self.find_world_quali_america_2014!() self.find_by_key!( WORLD_QUALI_AMERICA_2014 ) end
30
+
31
+ end # class Event
32
+
33
+
34
+ end # module Model
35
+ end # module SportDb
@@ -4,7 +4,7 @@ module SportDb
4
4
  class Deleter
5
5
  ######
6
6
  # NB: make models available in sportdb module by default with namespace
7
- # e.g. lets you use Team instead of Models::Team
7
+ # e.g. lets you use Team instead of Model::Team
8
8
  include SportDb::Models
9
9
 
10
10
  def run
@@ -35,7 +35,7 @@ class Reader
35
35
 
36
36
 
37
37
  ## make models available in sportdb module by default with namespace
38
- # e.g. lets you use Team instead of Models::Team
38
+ # e.g. lets you use Team instead of Model::Team
39
39
  include SportDb::Models
40
40
  include SportDb::Matcher # lets us use match_teams_for_country etc.
41
41
 
@@ -373,13 +373,21 @@ class Reader
373
373
  elsif key == 'grounds' || key == 'stadiums' || key == 'venues'
374
374
  ## assume grounds value is an array
375
375
 
376
+ ##
377
+ ## note: for now we allow invalid ground keys
378
+ ## will skip keys not found
379
+
376
380
  ground_ids = []
377
381
  value.each do |item|
378
382
  ground_key = item.to_s.strip
379
- ground = Ground.find_by_key!( ground_key )
380
- ground_ids << ground.id
383
+ ground = Ground.find_by_key( ground_key )
384
+ if ground.nil?
385
+ puts "[warn] ground/stadium w/ key >#{ground_key}< not found; skipping ground"
386
+ else
387
+ ground_ids << ground.id
388
+ end
381
389
  end
382
-
390
+
383
391
  event_attribs['ground_ids'] = ground_ids
384
392
  elsif key == 'teams'
385
393
  ## assume teams value is an array
@@ -7,7 +7,7 @@ module SportDb
7
7
 
8
8
  ######
9
9
  # NB: make models available in sportdb module by default with namespace
10
- # e.g. lets you use Team instead of Models::Team
10
+ # e.g. lets you use Team instead of Model::Team
11
11
  include SportDb::Models
12
12
 
13
13
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.8.5'
3
+ VERSION = '1.8.6'
4
4
  end
5
5
 
6
6
 
@@ -25,6 +25,15 @@ require 'logutils/db' # NB: explict require required for LogDb (not automatic)
25
25
  require 'sportdb'
26
26
 
27
27
 
28
+ #######################
29
+ #
30
+ # for reuse
31
+ # --- move to sportdb/test.rb ???
32
+ # SportDb.setup_in_memory_db ??? why? why not?? or
33
+ # SportDb.setup_test_db - alias ??
34
+
35
+
36
+
28
37
  def setup_in_memory_db
29
38
  # Database Setup & Config
30
39
 
@@ -49,5 +58,12 @@ def setup_in_memory_db
49
58
  SportDb.create
50
59
  end
51
60
 
61
+ ####
62
+ # Models shortcuts
63
+
64
+ Game = SportDb::Model::Game
65
+ GameCursor = SportDb::Model::GameCursor
66
+
67
+
52
68
 
53
69
  setup_in_memory_db()
@@ -5,11 +5,11 @@ require 'helper'
5
5
  class TestChanges < MiniTest::Unit::TestCase
6
6
 
7
7
  def test_scores
8
- game1 = SportDb::Models::Game.new
8
+ game1 = Game.new
9
9
  game1.score1 = 1
10
10
  game1.score2 = 2
11
11
 
12
- game2 = SportDb::Models::Game.new
12
+ game2 = Game.new
13
13
  game2.score1 = 1
14
14
  game2.score2 = 1
15
15
  game2.score1p = 5
@@ -29,12 +29,12 @@ class TestChanges < MiniTest::Unit::TestCase
29
29
  end
30
30
 
31
31
  def test_play_at
32
- game1 = SportDb::Models::Game.new
32
+ game1 = Game.new
33
33
  game1.score1 = 1
34
34
  game1.score2 = 2
35
35
  game1.play_at = DateTime.new( 2012, 11, 5 )
36
36
 
37
- game2 = SportDb::Models::Game.new
37
+ game2 = Game.new
38
38
  game2.score1 = 1
39
39
  game2.score2 = 2
40
40
  game2.play_at = DateTime.new( 2012, 12, 24 )
@@ -50,12 +50,12 @@ class TestChanges < MiniTest::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_group_id
53
- game1 = SportDb::Models::Game.new
53
+ game1 = Game.new
54
54
  game1.score1 = 1
55
55
  game1.score2 = 2
56
56
  game1.group_id = 1
57
57
 
58
- game2 = SportDb::Models::Game.new
58
+ game2 = Game.new
59
59
  game2.score1 = 1
60
60
  game2.score2 = 2
61
61
  game2.group_id = 2
@@ -7,12 +7,12 @@ class TestCursor < MiniTest::Unit::TestCase
7
7
  def test_games
8
8
  games = []
9
9
 
10
- games << SportDb::Models::Game.new( score1: 3, score2: 1, play_at: DateTime.new(2013, 8, 9) )
11
- games << SportDb::Models::Game.new( score1: 1, score2: 3, play_at: DateTime.new(2013, 8, 10) )
12
- games << SportDb::Models::Game.new( score1: 2, score2: 0, play_at: DateTime.new(2013, 8, 10) )
13
- games << SportDb::Models::Game.new( score1: 3, score2: 2, play_at: DateTime.new(2013, 8, 12) ) # new_week
10
+ games << Game.new( score1: 3, score2: 1, play_at: DateTime.new(2013, 8, 9) )
11
+ games << Game.new( score1: 1, score2: 3, play_at: DateTime.new(2013, 8, 10) )
12
+ games << Game.new( score1: 2, score2: 0, play_at: DateTime.new(2013, 8, 10) )
13
+ games << Game.new( score1: 3, score2: 2, play_at: DateTime.new(2013, 8, 12) ) # new_week
14
14
 
15
- SportDb::Models::GameCursor.new( games ).each do |game,state|
15
+ GameCursor.new( games ).each do |game,state|
16
16
  if state.index == 0
17
17
  assert_equal 3, game.score1
18
18
  assert_equal 1, game.score2
@@ -5,7 +5,7 @@ require 'helper'
5
5
  class TestWinner < MiniTest::Unit::TestCase
6
6
 
7
7
  def test_1_2
8
- game = SportDb::Models::Game.new
8
+ game = Game.new
9
9
  game.score1 = 1
10
10
  game.score2 = 2
11
11
  game.calc_winner
@@ -18,7 +18,7 @@ class TestWinner < MiniTest::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_1_1
21
- game = SportDb::Models::Game.new
21
+ game = Game.new
22
22
  game.score1 = 1
23
23
  game.score2 = 1
24
24
  game.calc_winner
@@ -31,7 +31,7 @@ class TestWinner < MiniTest::Unit::TestCase
31
31
  end
32
32
 
33
33
  def test_2_1
34
- game = SportDb::Models::Game.new
34
+ game = Game.new
35
35
  game.score1 = 2
36
36
  game.score2 = 1
37
37
  game.calc_winner
@@ -44,7 +44,7 @@ class TestWinner < MiniTest::Unit::TestCase
44
44
  end
45
45
 
46
46
  def test_1_1__2_1
47
- game = SportDb::Models::Game.new
47
+ game = Game.new
48
48
  game.score1 = 1
49
49
  game.score2 = 1
50
50
  game.score1et = 2
@@ -59,7 +59,7 @@ class TestWinner < MiniTest::Unit::TestCase
59
59
  end
60
60
 
61
61
  def test_1_1__2_2__3_5
62
- game = SportDb::Models::Game.new
62
+ game = Game.new
63
63
  game.score1 = 1
64
64
  game.score2 = 1
65
65
  game.score1et = 2
@@ -76,7 +76,7 @@ class TestWinner < MiniTest::Unit::TestCase
76
76
  end
77
77
 
78
78
  def test_1_1_x_3_5
79
- game = SportDb::Models::Game.new
79
+ game = Game.new
80
80
  game.score1 = 1
81
81
  game.score2 = 1
82
82
  game.score1et = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.5
4
+ version: 1.8.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-16 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &20942556 !ruby/object:Gem::Requirement
16
+ requirement: &20428068 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20942556
24
+ version_requirements: *20428068
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fetcher
27
- requirement: &20939616 !ruby/object:Gem::Requirement
27
+ requirement: &20427156 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20939616
35
+ version_requirements: *20427156
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gli
38
- requirement: &20837484 !ruby/object:Gem::Requirement
38
+ requirement: &20426016 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.5.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20837484
46
+ version_requirements: *20426016
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &20834256 !ruby/object:Gem::Requirement
49
+ requirement: &20424108 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '4.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20834256
57
+ version_requirements: *20424108
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &20832636 !ruby/object:Gem::Requirement
60
+ requirement: &20455920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.7'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20832636
68
+ version_requirements: *20455920
69
69
  description: sportdb - sport.db command line tool
70
70
  email: opensport@googlegroups.com
71
71
  executables: