Permalink
Browse files

make ground key optional

  • Loading branch information...
geraldb committed Feb 18, 2014
1 parent dc07fdd commit 7ab2954da6c8b5449d3a001b725326c1cbb6b7f1
View
@@ -128,6 +128,25 @@ EXAMPLES
~~~
+## Usage in Ruby (Console / Interactive Shell)
+
+
+Try the built-in console script. In your interactive Ruby shell type:
+
+ >> require 'sportdb/console'
+ # => Welcome to sport.db, version 1.9.7 (world.db, version 1.9.3)!
+
+This will try to connect to the `sport.db` SQLite database in your working folder.
+To get started try some queries, for example:
+
+ >> Team.count
+ # => 157
+ >> t = Team.find_by_key( 'barcelona' )
+ # => ...
+
+and so on.
+
+
## Install
View
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
require 'sportdb'
-SportDb.main
+
+SportDb.main
View
@@ -266,9 +266,10 @@ def connect_to_db( options )
command :stats do |c|
c.action do |g,o,args|
- connect_to_db( opts )
+ connect_to_db( opts )
SportDb.tables
+ WorldDb.tables
puts 'Done.'
end
View
@@ -17,30 +17,31 @@
##
## todo/fix: just use include SportDb::Models - why? why not? is it possible/working?
-Badge = SportDb::Models::Badge
-Event = SportDb::Models::Event
-Game = SportDb::Models::Game
-Goal = SportDb::Models::Goal
-Group = SportDb::Models::Group
-League = SportDb::Models::League
-Person = SportDb::Models::Person
-Race = SportDb::Models::Race
-Record = SportDb::Models::Record
-Roster = SportDb::Models::Roster
-Round = SportDb::Models::Round
-Run = SportDb::Models::Run
-Season = SportDb::Models::Season
-Team = SportDb::Models::Team
-Track = SportDb::Models::Track
-
-
-Tag = WorldDb::Models::Tag
-Tagging = WorldDb::Models::Tagging
-Continent = WorldDb::Models::Continent
-Country = WorldDb::Models::Country
-Region = WorldDb::Models::Region
-City = WorldDb::Models::City
-Prop = WorldDb::Models::Prop
+Badge = SportDb::Model::Badge
+Event = SportDb::Model::Event
+Game = SportDb::Model::Game
+Goal = SportDb::Model::Goal
+Group = SportDb::Model::Group
+League = SportDb::Model::League
+Person = SportDb::Model::Person
+Race = SportDb::Model::Race
+Record = SportDb::Model::Record
+Roster = SportDb::Model::Roster
+Round = SportDb::Model::Round
+Run = SportDb::Model::Run
+Season = SportDb::Model::Season
+Team = SportDb::Model::Team
+Track = SportDb::Model::Track
+
+
+Tag = WorldDb::Model::Tag
+Tagging = WorldDb::Model::Tagging
+Continent = WorldDb::Model::Continent
+Country = WorldDb::Model::Country
+Region = WorldDb::Model::Region
+City = WorldDb::Model::City
+Prop = WorldDb::Model::Prop
+
## connect to db
@@ -56,9 +57,17 @@
puts "Welcome to sport.db, version #{SportDb::VERSION} (world.db, version #{WorldDb::VERSION})!"
+## print tables stats (e.g. no of records)
+puts 'sport.db'
+puts '--------'
SportDb.tables
-puts "Ready."
+puts 'world.db'
+puts '--------'
+WorldDb.tables
+
+puts 'Ready.'
+
## add some predefined shortcuts
View
@@ -1,34 +1,42 @@
# encoding: utf-8
+
### todo/fix: move to sportdb-data gem/plugin/addon ??
+### fix: rename to ::Key (singular) - why? why not??
-### fix: rename to ::Key (singular) - why? why not??
+module SportDb
+
+ module EventKeys
+ # use constants for known keys; lets us define aliases (if things change)
+ AT_2011_12 = 'at.2011/12'
+ AT_2012_13 = 'at.2012/13'
+ AT_2013_14 = 'at.2013/14'
+
+ AT_CUP_2012_13 = 'at.cup.2012/13'
+ AT_CUP_2013_14 = 'at.cup.2013/14'
+
+ CL_2012_13 = 'cl.2012/13'
+ CL_2013_14 = 'cl.2013/14'
+
+ EURO_2008 = 'euro.2008'
+ EURO_2012 = 'euro.2012'
+
+ WORLD_2010 = 'world.2010'
+ WORLD_2014 = 'world.2014'
+
+ WORLD_QUALI_EUROPE_2014 = 'world.quali.europe.2014'
+ WORLD_QUALI_AMERICA_2014 = 'world.quali.america.2014'
+
+ ##################################################################
+ # NB: see github/openfootball (leagues.txt) for keys in use
+ end # module EventKeys
+
+
+
+ module Keys
+ ## all keys - used by anybody? really needed? check back later
+ include EventKeys
+ end
-module SportDb::Keys
-
- module EventKeys
- # use constants for known keys; lets us define aliases (if things change)
-
-
- AT_2011_12 = 'at.2011/12'
- AT_2012_13 = 'at.2012/13'
- AT_CUP_2012_13 = 'at.cup.2012/13'
-
- CL_2012_13 = 'cl.2012/13'
-
- EURO_2008 = 'euro.2008'
- EURO_2012 = 'euro.2012'
-
- WORLD_2010 = 'world.2010'
-
- WORLD_QUALI_EUROPE_2014 = 'world.quali.europe.2014'
- WORLD_QUALI_AMERICA_2014 = 'world.quali.america.2014'
-
- ############################
- ## NB: see db/leagues.rb for keys in use
- end
-
- include SportDb::Keys::EventKeys
-
-end # module SportDb::Keys
+end # module SportDb
View
@@ -1,43 +1,35 @@
# encoding: utf-8
-module SportDb::Model
-
- ## add convenience finders to some model classes
-
- class Event
-
- include SportDb::Keys::EventKeys
-
- def self.find_at_2012_13!
- self.find_by_key!( AT_2012_13 )
- end
-
- def self.find_at_cup_2012_13!
- self.find_by_key!( AT_CUP_2012_13 )
- end
-
- def self.find_cl_2012_13!
- self.find_by_key!( CL_2012_13 )
- end
-
- def self.find_euro_2012!
- self.find_by_key!( EURO_2012 )
- end
-
- def self.find_world_2010!
- self.find_by_key!( WORLD_2010 )
- end
-
- def self.find_world_quali_europe_2014!
- self.find_by_key!( WORLD_QUALI_EUROPE_2014 )
- end
-
- def self.find_world_quali_america_2014!
- self.find_by_key!( WORLD_QUALI_AMERICA_2014 )
- end
-
- end # class Event
-
-end # module SportDb::Model
+module SportDb
+ module Model
+## add convenience finders to some model classes
+
+class Event
+
+ include SportDb::EventKeys
+
+ def self.find_at_2012_13!() self.find_by_key!( AT_2012_13 ) end
+ def self.find_at_2013_14!() self.find_by_key!( AT_2013_14 ) end
+
+ def self.find_at_cup_2012_13!() self.find_by_key!( AT_CUP_2012_13 ) end
+ def self.find_at_cup_2013_14!() self.find_by_key!( AT_CUP_2013_14 ) end
+
+ def self.find_cl_2012_13!() self.find_by_key!( CL_2012_13 ) end
+ def self.find_cl_2013_14!() self.find_by_key!( CL_2013_14 ) end
+
+ def self.find_euro_2008!() self.find_by_key!( EURO_2008 ) end
+ def self.find_euro_2012!() self.find_by_key!( EURO_2012 ) end
+
+ def self.find_world_2010!() self.find_by_key!( WORLD_2010 ) end
+ def self.find_world_2014!() self.find_by_key!( WORLD_2014 ) end
+
+ def self.find_world_quali_europe_2014!() self.find_by_key!( WORLD_QUALI_EUROPE_2014 ) end
+ def self.find_world_quali_america_2014!() self.find_by_key!( WORLD_QUALI_AMERICA_2014 ) end
+
+end # class Event
+
+
+ end # module Model
+end # module SportDb
View
@@ -4,7 +4,7 @@ module SportDb
class Deleter
######
# NB: make models available in sportdb module by default with namespace
- # e.g. lets you use Team instead of Models::Team
+ # e.g. lets you use Team instead of Model::Team
include SportDb::Models
def run
View
@@ -35,7 +35,7 @@ class Reader
## make models available in sportdb module by default with namespace
-# e.g. lets you use Team instead of Models::Team
+# e.g. lets you use Team instead of Model::Team
include SportDb::Models
include SportDb::Matcher # lets us use match_teams_for_country etc.
@@ -373,13 +373,21 @@ def load_event( name )
elsif key == 'grounds' || key == 'stadiums' || key == 'venues'
## assume grounds value is an array
+ ##
+ ## note: for now we allow invalid ground keys
+ ## will skip keys not found
+
ground_ids = []
value.each do |item|
ground_key = item.to_s.strip
- ground = Ground.find_by_key!( ground_key )
- ground_ids << ground.id
+ ground = Ground.find_by_key( ground_key )
+ if ground.nil?
+ puts "[warn] ground/stadium w/ key >#{ground_key}< not found; skipping ground"
+ else
+ ground_ids << ground.id
+ end
end
-
+
event_attribs['ground_ids'] = ground_ids
elsif key == 'teams'
## assume teams value is an array
View
@@ -7,7 +7,7 @@ class Updater
######
# NB: make models available in sportdb module by default with namespace
- # e.g. lets you use Team instead of Models::Team
+ # e.g. lets you use Team instead of Model::Team
include SportDb::Models
View
@@ -1,6 +1,6 @@
module SportDb
- VERSION = '1.8.5'
+ VERSION = '1.8.6'
end
View
@@ -25,6 +25,15 @@
require 'sportdb'
+#######################
+#
+# for reuse
+# --- move to sportdb/test.rb ???
+# SportDb.setup_in_memory_db ??? why? why not?? or
+# SportDb.setup_test_db - alias ??
+
+
+
def setup_in_memory_db
# Database Setup & Config
@@ -49,5 +58,12 @@ def setup_in_memory_db
SportDb.create
end
+####
+# Models shortcuts
+
+Game = SportDb::Model::Game
+GameCursor = SportDb::Model::GameCursor
+
+
setup_in_memory_db()
View
@@ -5,11 +5,11 @@
class TestChanges < MiniTest::Unit::TestCase
def test_scores
- game1 = SportDb::Models::Game.new
+ game1 = Game.new
game1.score1 = 1
game1.score2 = 2
- game2 = SportDb::Models::Game.new
+ game2 = Game.new
game2.score1 = 1
game2.score2 = 1
game2.score1p = 5
@@ -29,12 +29,12 @@ def test_scores
end
def test_play_at
- game1 = SportDb::Models::Game.new
+ game1 = Game.new
game1.score1 = 1
game1.score2 = 2
game1.play_at = DateTime.new( 2012, 11, 5 )
- game2 = SportDb::Models::Game.new
+ game2 = Game.new
game2.score1 = 1
game2.score2 = 2
game2.play_at = DateTime.new( 2012, 12, 24 )
@@ -50,12 +50,12 @@ def test_play_at
end
def test_group_id
- game1 = SportDb::Models::Game.new
+ game1 = Game.new
game1.score1 = 1
game1.score2 = 2
game1.group_id = 1
- game2 = SportDb::Models::Game.new
+ game2 = Game.new
game2.score1 = 1
game2.score2 = 2
game2.group_id = 2
Oops, something went wrong.

0 comments on commit 7ab2954

Please sign in to comment.