Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use model ns

  • Loading branch information...
commit cc945738c37c7a99979987c8918529354b2d1eff 1 parent 2699448
@geraldb geraldb authored
Showing with 131 additions and 181 deletions.
  1. +4 −7 Manifest.txt
  2. +3 −3 README.md
  3. +1 −1  {lib/sportdb/data → attic}/fixtures.rb
  4. +1 −0  { → attic}/tasks/test.rb
  5. +12 −7 lib/sportdb.rb
  6. +2 −2 lib/sportdb/data/models.rb
  7. +3 −2 lib/sportdb/models/badge.rb
  8. +0 −14 lib/sportdb/models/city.rb
  9. +0 −18 lib/sportdb/models/country.rb
  10. +2 −2 lib/sportdb/models/event.rb
  11. +2 −2 lib/sportdb/models/event_team.rb
  12. +9 −9 lib/sportdb/models/forward.rb
  13. +14 −48 lib/sportdb/models/game.rb
  14. +2 −2 lib/sportdb/models/goal.rb
  15. +2 −2 lib/sportdb/models/group.rb
  16. +2 −2 lib/sportdb/models/group_team.rb
  17. +3 −3 lib/sportdb/models/league.rb
  18. +6 −10 lib/sportdb/models/person.rb
  19. +0 −7 lib/sportdb/models/prop.rb
  20. +2 −2 lib/sportdb/models/race.rb
  21. +2 −2 lib/sportdb/models/record.rb
  22. +0 −16 lib/sportdb/models/region.rb
  23. +4 −2 lib/sportdb/models/roster.rb
  24. +2 −2 lib/sportdb/models/round.rb
  25. +2 −2 lib/sportdb/models/run.rb
  26. +2 −2 lib/sportdb/models/season.rb
  27. +4 −4 lib/sportdb/models/team.rb
  28. +3 −3 lib/sportdb/models/track.rb
  29. +2 −2 lib/sportdb/models/utils.rb
  30. +12 −0 lib/sportdb/models/world/city.rb
  31. +2 −2 lib/sportdb/models/{ → world}/continent.rb
  32. +13 −0 lib/sportdb/models/world/country.rb
  33. +12 −0 lib/sportdb/models/world/region.rb
  34. +1 −1  lib/sportdb/version.rb
View
11 Manifest.txt
@@ -13,15 +13,11 @@ lib/sportdb.rb
lib/sportdb/cli/main.rb
lib/sportdb/cli/opts.rb
lib/sportdb/console.rb
-lib/sportdb/data/fixtures.rb
lib/sportdb/data/keys.rb
lib/sportdb/data/models.rb
lib/sportdb/deleter.rb
lib/sportdb/lang.rb
lib/sportdb/models/badge.rb
-lib/sportdb/models/city.rb
-lib/sportdb/models/continent.rb
-lib/sportdb/models/country.rb
lib/sportdb/models/event.rb
lib/sportdb/models/event_team.rb
lib/sportdb/models/forward.rb
@@ -31,10 +27,8 @@ lib/sportdb/models/group.rb
lib/sportdb/models/group_team.rb
lib/sportdb/models/league.rb
lib/sportdb/models/person.rb
-lib/sportdb/models/prop.rb
lib/sportdb/models/race.rb
lib/sportdb/models/record.rb
-lib/sportdb/models/region.rb
lib/sportdb/models/roster.rb
lib/sportdb/models/round.rb
lib/sportdb/models/run.rb
@@ -42,6 +36,10 @@ lib/sportdb/models/season.rb
lib/sportdb/models/team.rb
lib/sportdb/models/track.rb
lib/sportdb/models/utils.rb
+lib/sportdb/models/world/city.rb
+lib/sportdb/models/world/continent.rb
+lib/sportdb/models/world/country.rb
+lib/sportdb/models/world/region.rb
lib/sportdb/reader.rb
lib/sportdb/schema.rb
lib/sportdb/service.rb
@@ -79,7 +77,6 @@ lib/sportdb/title.rb
lib/sportdb/updater.rb
lib/sportdb/utils.rb
lib/sportdb/version.rb
-tasks/test.rb
test/helper.rb
test/test_changes.rb
test/test_cursor.rb
View
6 README.md
@@ -139,9 +139,9 @@ Just install the gem:
## Free Open Public Domain Datasets
- [`football.db`](https://github.com/openfootball) - free open public domain football (soccer) data for use in any (programming) language
-- [`formula1.db`](https://github.com/geraldb/formula1.db) - free open public domain Formula 1/Formula One data for use in any (programming) language
-- [`ski.db`](https://github.com/geraldb/ski.db) - free open public domain Ski Alpin/Alpine Ski data for use in any (programming) language
-- [`sport.db`](https://github.com/geraldb/sport.db) - free open public domain sports data for use in any (programming) language
+- [`formula1.db`](https://github.com/opensport/formula1.db) - free open public domain Formula 1/Formula One data for use in any (programming) language
+- [`ski.db`](https://github.com/opensport/ski.db) - free open public domain Ski Alpin/Alpine Ski data for use in any (programming) language
+- [`american-football.db`](https://github.com/opensport/american-football.db) - free open public domain American Football data for use in any (programming) language
## License
View
2  lib/sportdb/data/fixtures.rb → attic/fixtures.rb
@@ -202,4 +202,4 @@ def self.all
end # module Fixtures
-end # module SportDb
+end # module SportDb
View
1  tasks/test.rb → attic/tasks/test.rb
@@ -161,3 +161,4 @@ def import_fixtures( teams, fixtures )
$ rake -I ../world.db.ruby/lib -I ../sport.db.ruby/lib update
=end
+
View
19 lib/sportdb.rb
@@ -31,10 +31,11 @@
require 'sportdb/title' ## fix - move to textutils gem
require 'sportdb/models/forward'
+require 'sportdb/models/world/city'
+require 'sportdb/models/world/country'
+require 'sportdb/models/world/continent'
+require 'sportdb/models/world/region'
require 'sportdb/models/badge'
-require 'sportdb/models/city'
-require 'sportdb/models/country'
-require 'sportdb/models/continent'
require 'sportdb/models/event'
require 'sportdb/models/event_team'
require 'sportdb/models/game'
@@ -43,10 +44,8 @@
require 'sportdb/models/group_team'
require 'sportdb/models/league'
require 'sportdb/models/person'
-require 'sportdb/models/prop'
require 'sportdb/models/race'
require 'sportdb/models/record'
-require 'sportdb/models/region'
require 'sportdb/models/roster'
require 'sportdb/models/round'
require 'sportdb/models/run'
@@ -54,6 +53,13 @@
require 'sportdb/models/team'
require 'sportdb/models/track'
require 'sportdb/models/utils' # e.g. GameCursor
+
+## add backwards compatible namespace (delete later!)
+module SportDb
+ Models = Model
+end
+
+
require 'sportdb/schema' # NB: requires sportdb/models (include SportDB::Models)
require 'sportdb/utils'
require 'sportdb/reader'
@@ -72,7 +78,6 @@
# todo/fix => remove from here and move into console.rb and tasks.rb
require 'sportdb/data/keys'
-require 'sportdb/data/fixtures'
require 'sportdb/data/models' # add convenience finders for known fixtures
@@ -114,7 +119,7 @@ def self.main
def self.create
CreateDb.new.up
- WorldDb::Models::Prop.create!( key: 'db.schema.sport.version', value: VERSION )
+ WorldDb::Model::Prop.create!( key: 'db.schema.sport.version', value: VERSION )
end
def self.read_setup( setup, include_path )
View
4 lib/sportdb/data/models.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
-module SportDb::Models
+module SportDb::Model
## add convenience finders to some model classes
@@ -38,6 +38,6 @@ def self.find_world_quali_america_2014!
end # class Event
-end # module SportDb::Models
+end # module SportDb::Model
View
5 lib/sportdb/models/badge.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Badge < ActiveRecord::Base
@@ -9,4 +9,5 @@ class Badge < ActiveRecord::Base
end # class Badge
-end # module SportDb::Models
+end # module SportDb::Model
+
View
14 lib/sportdb/models/city.rb
@@ -1,14 +0,0 @@
-
-## todo: how to best extends city model?
-
-module WorldDb::Models
- class City
- has_many :teams, :class_name => 'SportDb::Models::Team', :foreign_key => 'city_id'
- end
-end # module WorldDb::Models
-
-
-## moved to models/forward
-# module SportDb::Models
-# City = WorldDb::Models::City
-# end # module SportDb::Models
View
18 lib/sportdb/models/country.rb
@@ -1,18 +0,0 @@
-# encoding: utf-8
-
-## todo: how to best extends country model?
-
-module WorldDb::Models
-
- class Country
- has_many :teams, :class_name => 'SportDb::Models::Team', :foreign_key => 'country_id'
- has_many :leagues, :class_name => 'SportDb::Models::League', :foreign_key => 'country_id'
- end # class Country
-
-end # module WorldDb::Models
-
-
-## moved to models/forward
-# module SportDb::Models
-# Country = WorldDb::Models::Country
-# end # module SportDb::Models
View
4 lib/sportdb/models/event.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
-module SportDb::Models
+module SportDb::Model
class Event < ActiveRecord::Base
@@ -54,4 +54,4 @@ def known_teams_table
end # class Event
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/event_team.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class EventTeam < ActiveRecord::Base
@@ -9,4 +9,4 @@ class EventTeam < ActiveRecord::Base
end # class EventTeam
-end # module SportDb::Models
+end # module SportDb::Model
View
18 lib/sportdb/models/forward.rb
@@ -2,15 +2,15 @@
### forward references
## require first to resolve circular references
-module SportDb::Models
+module SportDb::Model
## todo: why? why not use include WorldDb::Models here???
- Continent = WorldDb::Models::Continent
- Country = WorldDb::Models::Country
- Region = WorldDb::Models::Region
- City = WorldDb::Models::City
- Prop = WorldDb::Models::Prop
+ Continent = WorldDb::Model::Continent
+ Country = WorldDb::Model::Country
+ Region = WorldDb::Model::Region
+ City = WorldDb::Model::City
+ Prop = WorldDb::Model::Prop
## nb: for now only team and league use worlddb tables
# e.g. with belongs_to assoc (country,region)
@@ -21,12 +21,12 @@ class League < ActiveRecord::Base ; end
end
-module WorldDb::Models
+module WorldDb::Model
# add alias? why? why not? # is there a better way?
# - just include SportDb::Models - why? why not?
# - just include once in loader??
- Team = SportDb::Models::Team
- League = SportDb::Models::League
+ Team = SportDb::Model::Team
+ League = SportDb::Model::League
end
View
62 lib/sportdb/models/game.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Game < ActiveRecord::Base
@@ -86,53 +86,19 @@ def calc_winner
### getter/setters for deprecated attribs (score3,4,5,6) n national
- def score3
- score1et
- end
-
- def score4
- score2et
- end
-
- def score1ot
- score1et
- end
-
- def score2ot
- score2et
- end
-
- def score5
- score1p
- end
-
- def score6
- score2p
- end
+ def score3() score1et end
+ def score4() score2et end
+ def score1ot() score1et end
+ def score2ot() score2et end
+ def score5() score1p end
+ def score6() score2p end
- def score3=(value)
- self.score1et = value
- end
-
- def score4=(value)
- self.score2et = value
- end
-
- def score1ot=(value)
- self.score1et = value
- end
-
- def score2ot=(value)
- self.score2et = value
- end
-
- def score5=(value)
- self.score1p = value
- end
-
- def score6=(value)
- self.score2p = value
- end
+ def score3=(value) self.score1et = value end
+ def score4=(value) self.score2et = value end
+ def score1ot=(value) self.score1et = value end
+ def score2ot=(value) self.score2et = value end
+ def score5=(value) self.score1p = value end
+ def score6=(value) self.score2p = value end
@@ -391,4 +357,4 @@ def check_for_changes( new_attributes )
end # class Game
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/goal.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Goal < ActiveRecord::Base
@@ -9,4 +9,4 @@ class Goal < ActiveRecord::Base
end # class Goal
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/group.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Group < ActiveRecord::Base
@@ -19,5 +19,5 @@ def add_teams_from_ary!( team_keys )
end # class Group
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/group_team.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class GroupTeam < ActiveRecord::Base
@@ -9,5 +9,5 @@ class GroupTeam < ActiveRecord::Base
end # class GroupTeam
-end # module SportDb::Models
+end # module SportDb::Model
View
6 lib/sportdb/models/league.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class League < ActiveRecord::Base
@@ -10,7 +10,7 @@ class League < ActiveRecord::Base
has_many :events
has_many :seasons, :through => :events
- belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
+ belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
def self.create_or_update_from_values( new_attributes, values )
@@ -78,4 +78,4 @@ def self.create_from_ary!( leagues, more_values={} )
end # class League
-end # module SportDb::Models
+end # module SportDb::Model
View
16 lib/sportdb/models/person.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Person < ActiveRecord::Base
@@ -6,16 +6,11 @@ class Person < ActiveRecord::Base
has_many :goals
- belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
+ belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
- def title # alias for name
- name
- end
-
- def title=(value) # alias for name
- self.name = value
- end
+ def title() name end # alias for name
+ def title=(value) self.name = value end # alias for name
def self.create_or_update_from_values( new_attributes, values )
@@ -67,4 +62,5 @@ def self.create_or_update_from_values( new_attributes, values )
end # class Person
-end # module SportDb::Models
+end # module SportDb::Model
+
View
7 lib/sportdb/models/prop.rb
@@ -1,7 +0,0 @@
-# encoding: utf-8
-
-
-## moved to models/forward
-# module SportDb::Models
-# Prop = WorldDb::Models::Prop
-# end # module SportDb::Models
View
4 lib/sportdb/models/race.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Race < ActiveRecord::Base
@@ -13,4 +13,4 @@ class Race < ActiveRecord::Base
end # class Race
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/record.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Record < ActiveRecord::Base
@@ -10,4 +10,4 @@ class Record < ActiveRecord::Base
end # class Record
-end # module SportDb::Models
+end # module SportDb::Model
View
16 lib/sportdb/models/region.rb
@@ -1,16 +0,0 @@
-# encoding: utf-8
-
-## todo: how to best extends country model?
-
-module WorldDb::Models
-
- class Region
- has_many :teams, :class_name => 'SportDb::Models::Team', :through => :cities
- end # class Region
-
-end # module WorldDb::Models
-
-## moved to models/forward
-# module SportDb::Models
-# Region = WorldDb::Models::Region
-# end # module SportDb::Models
View
6 lib/sportdb/models/roster.rb
@@ -1,4 +1,6 @@
-module SportDb::Models
+module SportDb::Model
+
+### use LineUp, Squad for name? - alias??
class Roster < ActiveRecord::Base
@@ -9,4 +11,4 @@ class Roster < ActiveRecord::Base
end # class Roster
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/round.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Round < ActiveRecord::Base
@@ -9,5 +9,5 @@ class Round < ActiveRecord::Base
end # class Round
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/run.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Run < ActiveRecord::Base
@@ -8,4 +8,4 @@ class Run < ActiveRecord::Base
end # class Run
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/season.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Season < ActiveRecord::Base
@@ -8,4 +8,4 @@ class Season < ActiveRecord::Base
end # class Season
-end # module SportDb::Models
+end # module SportDb::Model
View
8 lib/sportdb/models/team.rb
@@ -1,4 +1,4 @@
-module SportDb::Models
+module SportDb::Model
class Team < ActiveRecord::Base
@@ -32,8 +32,8 @@ def past_games
has_many :badges # Winner, 2nd, Cupsieger, Aufsteiger, Absteiger, etc.
- belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
- belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
+ belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
+ belongs_to :city, :class_name => 'WorldDb::Model::City', :foreign_key => 'city_id'
@@ -129,4 +129,4 @@ def self.create_from_ary!( teams, more_values={} )
end # class Team
-end # module SportDb::Models
+end # module SportDb::Model
View
6 lib/sportdb/models/track.rb
@@ -1,10 +1,10 @@
-module SportDb::Models
+module SportDb::Model
class Track < ActiveRecord::Base
has_many :races
- belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
+ belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
#####################
## convenience helper for text parser/reader
@@ -55,4 +55,4 @@ def self.create_or_update_from_values( new_attributes, values )
end # class Track
-end # module SportDb::Models
+end # module SportDb::Model
View
4 lib/sportdb/models/utils.rb
@@ -1,5 +1,5 @@
module SportDb
- module Models
+ module Model
class GameCursor
@@ -74,5 +74,5 @@ def next( game )
end # class GameCursorState
- end # module Models
+ end # module Model
end # module SportDb
View
12 lib/sportdb/models/world/city.rb
@@ -0,0 +1,12 @@
+# encoding: utf-8
+
+## todo: how to best extends city model?
+
+module WorldDb::Model
+
+ class City
+ has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
+ end
+
+end # module WorldDb::Model
+
View
4 lib/sportdb/models/continent.rb → lib/sportdb/models/world/continent.rb
@@ -1,10 +1,10 @@
# encoding: utf-8
-module WorldDb::Models
+module WorldDb::Model
class Continent
has_many :teams, :through => :countries
has_many :leagues, :through => :countries
end # class Continent
-end # module WorldDb::Models
+end # module WorldDb::Model
View
13 lib/sportdb/models/world/country.rb
@@ -0,0 +1,13 @@
+# encoding: utf-8
+
+## todo: how to best extends country model?
+
+module WorldDb::Model
+
+ class Country
+ has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'country_id'
+ has_many :leagues, class_name: 'SportDb::Model::League', foreign_key: 'country_id'
+ end # class Country
+
+end # module WorldDb::Model
+
View
12 lib/sportdb/models/world/region.rb
@@ -0,0 +1,12 @@
+# encoding: utf-8
+
+## todo: how to best extends country model?
+
+module WorldDb::Model
+
+ class Region
+ has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
+ end # class Region
+
+end # module WorldDb::Model
+
View
2  lib/sportdb/version.rb
@@ -1,6 +1,6 @@
module SportDb
- VERSION = '1.8.0'
+ VERSION = '1.8.1'
end
Please sign in to comment.
Something went wrong with that request. Please try again.