/
market.rb
115 lines (88 loc) · 2.96 KB
/
market.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
## NB: do NOT require sportdb (avoid circular loading)
#### require 'sportdb'
require 'sportdb/market/version'
require 'sportdb/market/schema'
require 'sportdb/market/models/service'
require 'sportdb/market/models/group_quote'
require 'sportdb/market/models/event_quote'
require 'sportdb/market/models/quote'
require 'sportdb/market/models/game'
require 'sportdb/market/loader'
require 'sportdb/market/reader'
module SportDb::Market
def self.banner
"sportdb-market #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
end
## cut off folders lib(#1)/sportdb(#2) to get to root
def self.root
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
end
## builtin path to fixture data
def self.data_path
"#{root}/data"
end
def self.create
CreateDb.up
end
def self.fixtures_rb # all builtin ruby fixtures; helper for covenience
['services',
'at/2012_13/bl',
'at/2012_13/cup',
'cl/2012_13/cl',
## 'euro/2012'
]
end
def self.load_all
load( fixtures_rb )
end
def self.fixtures_txt
[['betathome', 'at.2012/13', 'at/2012_13/bl_betathome'],
['tipp3', 'at.2012/13', 'at/2012_13/bl_tipp3'],
['betathome', 'at.cup.2012/13', 'at/2012_13/cup_betathome'],
['tipp3', 'at.cup.2012/13', 'at/2012_13/cup_tipp3'],
['betathome', 'cl.2012/13', 'cl/2012_13/cl_betathome'],
['tipp3', 'cl.2012/13', 'cl/2012_13/cl_tipp3'],
## ['tipico', 'euro.2012', 'euro/2012_tipico'],
## ['tipp3', 'euro.2012', 'euro/2012_tipp3' ],
['tipp3', 'world.quali.europe.2014', 'world/quali_tipp3']]
end
def self.read_all
read( fixtures_txt )
end
# load built-in (that is, bundled within the gem) named seeds
# - pass in an array of seed names e.g. [ 'cl/teams', 'cl/2012_13/cl' ] etc.
def self.load( ary )
loader = Loader.new
ary.each do |name|
loader.load_builtin( name )
end
end
# load built-in (that is, bundled within the gem) named plain text seeds
# - pass in an array of pairs of event/seed names e.g. [['at.2012/13', 'at/2012_13/bl'], ['cl.2012/13', 'cl/2012_13/cl']] etc.
def self.read( ary )
reader = Reader.new
ary.each do |rec|
reader.load_builtin( rec[0], rec[1], rec[2] ) # service_key, event_key, name
end
end
class Deleter
## todo: move into its own file???
## make models available in sportdb module by default with namespace
# e.g. lets you use Team instead of Models::Team
include SportDb::Models
def run( args=[] )
# for now delete all tables
Service.delete_all
Quote.delete_all
GroupQuote.delete_all
EventQuote.delete_all
end
end
# delete ALL records (use with care!)
def self.delete!
puts '*** deleting sport market table records/data...'
Deleter.new.run
end # method delete!
end # module SportDb::Market
## say hello
puts SportDb::Market.banner