sportdb-models 1.18.5 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +27 -145
- data/Rakefile +4 -5
- data/lib/sportdb/models.rb +93 -160
- data/lib/sportdb/{deleter.rb → models/deleter.rb} +4 -10
- data/lib/sportdb/models/formats.rb +23 -0
- data/lib/sportdb/models/models/assoc.rb +38 -0
- data/lib/sportdb/models/{badge.rb → models/badge.rb} +1 -1
- data/lib/sportdb/models/models/event.rb +55 -0
- data/lib/sportdb/models/{forward.rb → models/forward.rb} +3 -3
- data/lib/sportdb/models/{goal.rb → models/goal.rb} +1 -1
- data/lib/sportdb/models/models/ground.rb +16 -0
- data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
- data/lib/sportdb/models/models/league.rb +20 -0
- data/lib/sportdb/models/{roster.rb → models/lineup.rb} +3 -4
- data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
- data/lib/sportdb/models/{person.rb → models/person.rb} +0 -0
- data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
- data/lib/sportdb/models/{season.rb → models/season.rb} +2 -1
- data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
- data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
- data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +11 -1
- data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
- data/lib/sportdb/models/models/team.rb +56 -0
- data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
- data/lib/sportdb/models/{world → models/world}/continent.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/state.rb +0 -0
- data/lib/sportdb/{schema.rb → models/schema.rb} +165 -100
- data/lib/sportdb/models/stats.rb +23 -0
- data/lib/sportdb/models/utils.rb +24 -24
- data/lib/sportdb/{version.rb → models/version.rb} +12 -5
- data/test/helper.rb +10 -114
- data/test/test_changes.rb +38 -38
- data/test/test_cursor.rb +15 -15
- data/test/test_winner.rb +75 -70
- metadata +29 -161
- data/lib/sportdb/calc.rb +0 -279
- data/lib/sportdb/indexers/team.rb +0 -87
- data/lib/sportdb/mapper_teams.rb +0 -24
- data/lib/sportdb/matcher.rb +0 -31
- data/lib/sportdb/models/assoc.rb +0 -106
- data/lib/sportdb/models/assoc_assoc.rb +0 -15
- data/lib/sportdb/models/event.rb +0 -66
- data/lib/sportdb/models/event_ground.rb +0 -15
- data/lib/sportdb/models/event_team.rb +0 -16
- data/lib/sportdb/models/ground.rb +0 -100
- data/lib/sportdb/models/group_team.rb +0 -14
- data/lib/sportdb/models/league.rb +0 -83
- data/lib/sportdb/models/stage_team.rb +0 -14
- data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
- data/lib/sportdb/models/stats/event_standing.rb +0 -55
- data/lib/sportdb/models/stats/group_standing.rb +0 -50
- data/lib/sportdb/models/team.rb +0 -119
- data/lib/sportdb/models/team_compat.rb +0 -64
- data/lib/sportdb/patterns.rb +0 -37
- data/lib/sportdb/pretty_printer.rb +0 -175
- data/lib/sportdb/reader.rb +0 -132
- data/lib/sportdb/reader_file.rb +0 -131
- data/lib/sportdb/reader_zip.rb +0 -172
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -253
- data/lib/sportdb/readers/event_meta.rb +0 -133
- data/lib/sportdb/readers/event_table.rb +0 -196
- data/lib/sportdb/readers/game.rb +0 -912
- data/lib/sportdb/readers/ground.rb +0 -53
- data/lib/sportdb/readers/league.rb +0 -54
- data/lib/sportdb/readers/season.rb +0 -83
- data/lib/sportdb/readers/squad_club.rb +0 -201
- data/lib/sportdb/readers/squad_national_team.rb +0 -173
- data/lib/sportdb/readers/team.rb +0 -53
- data/lib/sportdb/rsssf_reader.rb +0 -367
- data/lib/sportdb/standings.rb +0 -178
- data/lib/sportdb/stats.rb +0 -27
- data/lib/sportdb/utils.rb +0 -89
- data/lib/sportdb/utils_date.rb +0 -26
- data/lib/sportdb/utils_goals.rb +0 -20
- data/lib/sportdb/utils_group.rb +0 -63
- data/lib/sportdb/utils_map.rb +0 -44
- data/lib/sportdb/utils_round.rb +0 -165
- data/lib/sportdb/utils_scores.rb +0 -17
- data/lib/sportdb/utils_teams.rb +0 -48
- data/test/data/at-austria/2013_14/bl.txt +0 -227
- data/test/data/at-austria/2013_14/bl.yml +0 -30
- data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
- data/test/data/at-austria/2013_14/el.txt +0 -4
- data/test/data/at-austria/2013_14/el.yml +0 -25
- data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
- data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
- data/test/data/at-austria/2014_15/1-bundesliga-ii.txt +0 -158
- data/test/data/at-austria/2014_15/1-bundesliga.yml +0 -18
- data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga-v2.yml +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.yml +0 -24
- data/test/data/at-austria/2015_16/cup.yml +0 -77
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -68
- data/test/data/at-austria/teams_2.txt +0 -21
- data/test/data/csv/de-2013-14--1-bundesliga.txt +0 -307
- data/test/data/de-deutschland/2013-14/1-bundesliga.yml +0 -26
- data/test/data/de-deutschland/leagues.txt +0 -4
- data/test/data/de-deutschland/teams.txt +0 -53
- data/test/data/eng-england/2015-16/1-premierleague-v2.yml +0 -2
- data/test/data/eng-england/2015-16/1-premierleague.yml +0 -5
- data/test/data/national-teams/assocs.txt +0 -231
- data/test/data/national-teams/europe/assocs.txt +0 -13
- data/test/data/national-teams/europe/teams.txt +0 -13
- data/test/data/national-teams/north-america/assocs.txt +0 -10
- data/test/data/national-teams/north-america/teams.txt +0 -7
- data/test/data/national-teams/teams.txt +0 -19
- data/test/data/players/europe/at-austria/players.txt +0 -45
- data/test/data/players/europe/de-deutschland/players.txt +0 -41
- data/test/data/players/south-america/br-brazil/players.txt +0 -51
- data/test/data/rsssf/at-2014-15--1-bundesliga.txt +0 -339
- data/test/data/rsssf/at-2015-16--1-bundesliga.txt +0 -18
- data/test/data/world-cup/1930/cup.txt +0 -71
- data/test/data/world-cup/1930/cup.yml +0 -23
- data/test/data/world-cup/1930/cup_goals.txt +0 -47
- data/test/data/world-cup/1930/cup_goals.yml +0 -23
- data/test/data/world-cup/1954/cup.txt +0 -90
- data/test/data/world-cup/1954/cup.yml +0 -30
- data/test/data/world-cup/1962/cup.txt +0 -86
- data/test/data/world-cup/1962/cup.yml +0 -32
- data/test/data/world-cup/1974/cup.yml +0 -35
- data/test/data/world-cup/1974/cup_finals.txt +0 -14
- data/test/data/world-cup/1974/cup_i.txt +0 -55
- data/test/data/world-cup/1974/cup_ii.txt +0 -34
- data/test/data/world-cup/2014/cup.txt +0 -5
- data/test/data/world-cup/2014/cup.yml +0 -54
- data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
- data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
- data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
- data/test/data/world-cup/leagues.txt +0 -5
- data/test/data/world-cup/seasons_1930.txt +0 -4
- data/test/data/world-cup/seasons_1954.txt +0 -4
- data/test/data/world-cup/seasons_1962.txt +0 -4
- data/test/data/world-cup/seasons_1974.txt +0 -5
- data/test/data/world-cup/teams_1930.txt +0 -26
- data/test/data/world-cup/teams_1954.txt +0 -30
- data/test/data/world-cup/teams_1962.txt +0 -29
- data/test/data/world-cup/teams_1974.txt +0 -29
- data/test/test_assoc_reader.rb +0 -199
- data/test/test_event_meta_reader.rb +0 -47
- data/test/test_event_reader.rb +0 -64
- data/test/test_event_table_reader.rb +0 -57
- data/test/test_goals.rb +0 -107
- data/test/test_indexer_team.rb +0 -34
- data/test/test_load.rb +0 -61
- data/test/test_pp.rb +0 -35
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -63
- data/test/test_round_auto.rb +0 -370
- data/test/test_round_def.rb +0 -109
- data/test/test_round_header.rb +0 -183
- data/test/test_rsssf_reader.rb +0 -76
- data/test/test_squad_club_reader.rb +0 -76
- data/test/test_squad_national_team_reader.rb +0 -116
- data/test/test_standings.rb +0 -279
- data/test/test_standings_ii.rb +0 -46
- data/test/test_utils.rb +0 -124
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
|
4
|
+
class Stats
|
5
|
+
include Models
|
6
|
+
|
7
|
+
def tables
|
8
|
+
puts " #{League.count} leagues / #{Season.count} seasons"
|
9
|
+
puts " #{Event.count} events (league+season recs) / #{Round.count} rounds / #{Group.count} groups / #{Stage.count} stages"
|
10
|
+
puts " #{Team.count} teams"
|
11
|
+
puts " #{Match.count} matches"
|
12
|
+
puts " #{Badge.count} badges"
|
13
|
+
|
14
|
+
puts " #{Lineup.count} lineups (person+team+event recs)"
|
15
|
+
puts " #{Goal.count} goals (person+match recs)"
|
16
|
+
|
17
|
+
puts " #{Assoc.count} assocs|orgs"
|
18
|
+
puts " #{Ground.count} grounds|stadiums"
|
19
|
+
end
|
20
|
+
|
21
|
+
end # class Stats
|
22
|
+
|
23
|
+
end # module SportDb
|
data/lib/sportdb/models/utils.rb
CHANGED
@@ -2,27 +2,27 @@ module SportDb
|
|
2
2
|
module Model
|
3
3
|
|
4
4
|
|
5
|
-
class
|
5
|
+
class MatchCursor
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize( matches )
|
8
|
+
@matches = matches
|
9
9
|
end
|
10
10
|
|
11
11
|
def each
|
12
|
-
state =
|
12
|
+
state = MatchCursorState.new
|
13
13
|
|
14
|
-
@
|
15
|
-
state.next(
|
16
|
-
yield(
|
14
|
+
@matches.each do |match|
|
15
|
+
state.next( match )
|
16
|
+
yield( match, state ) # e.g. lets you use state.new_date? or state.new_week? or state.new_year? etc.
|
17
17
|
end
|
18
18
|
end # method each
|
19
|
-
end # class
|
19
|
+
end # class MatchCursor
|
20
20
|
|
21
21
|
|
22
|
-
class
|
22
|
+
class MatchCursorState
|
23
23
|
|
24
24
|
def initialize
|
25
|
-
@
|
25
|
+
@last_date = DateTime.new( 1971, 1, 1 )
|
26
26
|
@new_date = true
|
27
27
|
@new_year = true
|
28
28
|
@new_week = true
|
@@ -34,44 +34,44 @@ class GameCursorState
|
|
34
34
|
def new_date?() @new_date; end
|
35
35
|
def new_year?() @new_year; end
|
36
36
|
def new_week?() @new_week; end
|
37
|
-
|
37
|
+
|
38
38
|
|
39
39
|
## add new league ?
|
40
40
|
## add new round ?
|
41
41
|
## add new time ?
|
42
|
-
|
43
|
-
def next(
|
42
|
+
|
43
|
+
def next( match )
|
44
44
|
@index += 1 # zero-based index; start off with -1 (undefined/uninitialized)
|
45
|
-
|
45
|
+
match_date = match.date # cache date value ref
|
46
46
|
|
47
|
-
if @
|
48
|
-
@
|
49
|
-
@
|
47
|
+
if @last_date.year == match_date.year &&
|
48
|
+
@last_date.month == match_date.month &&
|
49
|
+
@last_date.day == match_date.day
|
50
50
|
@new_date = false
|
51
51
|
else
|
52
52
|
@new_date = true
|
53
|
-
|
53
|
+
|
54
54
|
# check for new_year
|
55
|
-
if @
|
55
|
+
if @last_date.year == match_date.year
|
56
56
|
@new_year = false
|
57
57
|
else
|
58
58
|
@new_year = true
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# check for new_week
|
62
62
|
# -- todo: find a method for week number; do NOT use strftime; there must be something easier
|
63
63
|
# -- check if activesupport adds .week or similar ??? use it if it exists
|
64
|
-
if @
|
64
|
+
if @last_date.strftime('%V') == match_date.strftime('%V')
|
65
65
|
@new_week = false
|
66
66
|
else
|
67
67
|
@new_week = true
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
@
|
71
|
+
@last_date = match.date
|
72
72
|
end # method next
|
73
|
-
|
74
|
-
end # class
|
73
|
+
|
74
|
+
end # class MatchCursorState
|
75
75
|
|
76
76
|
|
77
77
|
end # module Model
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module SportDb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Module
|
5
|
+
module Models
|
6
|
+
MAJOR = 2
|
7
|
+
MINOR = 0
|
8
|
+
PATCH = 1
|
8
9
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
10
|
|
10
11
|
def self.version
|
@@ -16,7 +17,13 @@ module SportDb
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.root
|
19
|
-
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
20
|
+
"#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
|
20
21
|
end
|
21
22
|
|
23
|
+
end # module Models
|
24
|
+
end # module Module
|
25
|
+
|
26
|
+
#################
|
27
|
+
## add convenience shortcuts
|
28
|
+
VERSION = Module::Models::VERSION
|
22
29
|
end # module SportDb
|
data/test/helper.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
|
-
|
2
|
-
## $:.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
1
|
## minitest setup
|
5
|
-
|
6
2
|
require 'minitest/autorun'
|
7
3
|
|
8
4
|
|
9
5
|
## our own code
|
10
|
-
|
11
6
|
require 'sportdb/models'
|
12
7
|
|
13
8
|
|
@@ -22,15 +17,15 @@ League = SportDb::Model::League
|
|
22
17
|
Season = SportDb::Model::Season
|
23
18
|
Event = SportDb::Model::Event
|
24
19
|
Team = SportDb::Model::Team
|
25
|
-
|
20
|
+
Lineup = SportDb::Model::Lineup
|
26
21
|
Assoc = SportDb::Model::Assoc
|
27
22
|
AssocAssoc = SportDb::Model::AssocAssoc
|
28
23
|
|
29
|
-
Round
|
30
|
-
Group
|
31
|
-
Stage
|
32
|
-
|
33
|
-
|
24
|
+
Round = SportDb::Model::Round
|
25
|
+
Group = SportDb::Model::Group
|
26
|
+
Stage = SportDb::Model::Stage
|
27
|
+
Match = SportDb::Model::Match
|
28
|
+
MatchCursor = SportDb::Model::MatchCursor
|
34
29
|
|
35
30
|
|
36
31
|
EventStanding = SportDb::Model::EventStanding
|
@@ -41,110 +36,11 @@ AlltimeStanding = SportDb::Model::AlltimeStanding
|
|
41
36
|
AlltimeStandingEntry = SportDb::Model::AlltimeStandingEntry
|
42
37
|
|
43
38
|
|
44
|
-
|
45
|
-
####################
|
46
|
-
# Reader shortcuts
|
47
|
-
|
48
|
-
Reader = SportDb::Reader
|
49
|
-
TeamReader = SportDb::TeamReader
|
50
|
-
TeamIndexer = SportDb::TeamIndexer
|
51
|
-
AssocReader = SportDb::AssocReader
|
52
|
-
SeasonReader = SportDb::SeasonReader
|
53
|
-
LeagueReader = SportDb::LeagueReader
|
54
|
-
EventReader = SportDb::EventReader
|
55
|
-
EventMetaReader = SportDb::EventMetaReader
|
56
|
-
EventTableReader = SportDb::EventTableReader
|
57
|
-
GameReader = SportDb::GameReader
|
58
|
-
NationalTeamSquadReader = SportDb::NationalTeamSquadReader
|
59
|
-
ClubSquadReader = SportDb::ClubSquadReader
|
60
|
-
|
61
|
-
## moved to racing.db - remove/delete!!
|
62
|
-
## RaceTeamReader = SportDb::RaceTeamReader
|
63
|
-
|
64
|
-
PersonReader = PersonDb::PersonReader
|
65
|
-
|
66
|
-
######
|
67
|
-
# New Reader ShortCuts
|
68
|
-
|
69
|
-
module TestPrettyPrinter
|
70
|
-
def self.from_file( name, opts={} )
|
71
|
-
SportDb::PrettyPrinter.from_file( "#{SportDb.test_data_path}/#{name}.txt", opts )
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
module TestTeamReader
|
77
|
-
def self.from_file( name, more_attribs={} )
|
78
|
-
TeamReader.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
module TestTeamIndexer
|
83
|
-
def self.from_file( name, more_attribs={} )
|
84
|
-
TeamIndexer.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
module TestClubSquadReader
|
90
|
-
def self.from_file( name, more_attribs={} )
|
91
|
-
ClubSquadReader.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
module TestNationalTeamSquadReader
|
96
|
-
def self.from_file( name, more_attribs={} )
|
97
|
-
NationalTeamSquadReader.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
module TestLeagueReader
|
102
|
-
def self.from_file( name, more_attribs={} )
|
103
|
-
LeagueReader.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
module TestSeasonReader
|
108
|
-
def self.from_file( name )
|
109
|
-
SeasonReader.from_file( "#{SportDb.test_data_path}/#{name}.txt" )
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
module TestEventReader
|
114
|
-
def self.from_file( name )
|
115
|
-
EventReader.from_file( "#{SportDb.test_data_path}/#{name}.yml" )
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
module TestEventMetaReader
|
120
|
-
def self.from_file( name )
|
121
|
-
EventMetaReader.from_file( "#{SportDb.test_data_path}/#{name}.yml" )
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
module TestEventTableReader
|
126
|
-
def self.from_file( name )
|
127
|
-
EventTableReader.from_file( "#{SportDb.test_data_path}/#{name}.txt" )
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
module TestGameReader
|
133
|
-
## NOTE: pass in .yml as path (that is, event config!!!!)
|
134
|
-
def self.from_file( name, more_attribs={} )
|
135
|
-
GameReader.from_file( "#{SportDb.test_data_path}/#{name}.yml", more_attribs )
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
module TestAssocReader
|
140
|
-
def self.from_file( name )
|
141
|
-
AssocReader.from_file( "#{SportDb.test_data_path}/#{name}.txt" )
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
39
|
#################################
|
148
40
|
# setup db -> schema / tables
|
149
41
|
|
150
42
|
SportDb.setup_in_memory_db
|
43
|
+
|
44
|
+
## test helpers here
|
45
|
+
SportDb.delete!
|
46
|
+
SportDb.tables
|
data/test/test_changes.rb
CHANGED
@@ -8,18 +8,18 @@ require 'helper'
|
|
8
8
|
|
9
9
|
class TestChanges < MiniTest::Test
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
def test_score
|
12
|
+
match1 = Match.new
|
13
|
+
match1.score1 = 1
|
14
|
+
match1.score2 = 2
|
15
|
+
|
16
|
+
match2 = Match.new
|
17
|
+
match2.score1 = 1
|
18
|
+
match2.score2 = 1
|
19
|
+
match2.score1p = 5
|
20
|
+
match2.score2p = 3
|
21
|
+
|
22
|
+
match_attribs = {
|
23
23
|
score1: 1,
|
24
24
|
score2: 2,
|
25
25
|
score1et: nil,
|
@@ -28,50 +28,50 @@ class TestChanges < MiniTest::Test
|
|
28
28
|
score2p: nil
|
29
29
|
}
|
30
30
|
|
31
|
-
assert_equal false,
|
32
|
-
assert_equal true,
|
31
|
+
assert_equal false, match1.check_for_changes( match_attribs )
|
32
|
+
assert_equal true, match2.check_for_changes( match_attribs )
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def test_date
|
36
|
+
match1 = Match.new
|
37
|
+
match1.score1 = 1
|
38
|
+
match1.score2 = 2
|
39
|
+
match1.date = Date.new( 2012, 11, 5 )
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
match2 = Match.new
|
42
|
+
match2.score1 = 1
|
43
|
+
match2.score2 = 2
|
44
|
+
match2.date = DateTime.new( 2012, 12, 24 )
|
45
45
|
|
46
|
-
|
46
|
+
match_attribs = {
|
47
47
|
score1: 1,
|
48
48
|
score2: 2,
|
49
|
-
|
49
|
+
date: DateTime.new( 2012, 11, 5 )
|
50
50
|
}
|
51
51
|
|
52
|
-
assert_equal false,
|
53
|
-
assert_equal true,
|
52
|
+
assert_equal false, match1.check_for_changes( match_attribs )
|
53
|
+
assert_equal true, match2.check_for_changes( match_attribs )
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_group_id
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
match1 = Match.new
|
58
|
+
match1.score1 = 1
|
59
|
+
match1.score2 = 2
|
60
|
+
match1.group_id = 1
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
match2 = Match.new
|
63
|
+
match2.score1 = 1
|
64
|
+
match2.score2 = 2
|
65
|
+
match2.group_id = 2
|
66
66
|
|
67
|
-
|
67
|
+
match_attribs = {
|
68
68
|
score1: 1,
|
69
69
|
score2: 2,
|
70
70
|
group_id: 1
|
71
71
|
}
|
72
72
|
|
73
|
-
assert_equal false,
|
74
|
-
assert_equal true,
|
73
|
+
assert_equal false, match1.check_for_changes( match_attribs )
|
74
|
+
assert_equal true, match2.check_for_changes( match_attribs )
|
75
75
|
end
|
76
76
|
|
77
77
|
|
data/test/test_cursor.rb
CHANGED
@@ -9,42 +9,42 @@ require 'helper'
|
|
9
9
|
|
10
10
|
class TestCursor < MiniTest::Test
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def test_matches
|
13
|
+
matches = []
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
matches << Match.new( score1: 3, score2: 1, date: Date.new(2013, 8, 9) )
|
16
|
+
matches << Match.new( score1: 1, score2: 3, date: Date.new(2013, 8, 10) )
|
17
|
+
matches << Match.new( score1: 2, score2: 0, date: Date.new(2013, 8, 10) )
|
18
|
+
matches << Match.new( score1: 3, score2: 2, date: Date.new(2013, 8, 12) ) # new_week
|
19
19
|
|
20
|
-
|
20
|
+
MatchCursor.new( matches ).each do |match,state|
|
21
21
|
if state.index == 0
|
22
|
-
assert_equal 3,
|
23
|
-
assert_equal 1,
|
22
|
+
assert_equal 3, match.score1
|
23
|
+
assert_equal 1, match.score2
|
24
24
|
assert_equal true, state.new_date?
|
25
25
|
assert_equal true, state.new_year?
|
26
26
|
assert_equal true, state.new_week?
|
27
27
|
end
|
28
28
|
|
29
29
|
if state.index == 1
|
30
|
-
assert_equal 1,
|
31
|
-
assert_equal 3,
|
30
|
+
assert_equal 1, match.score1
|
31
|
+
assert_equal 3, match.score2
|
32
32
|
assert_equal true, state.new_date?
|
33
33
|
assert_equal false, state.new_year?
|
34
34
|
assert_equal false, state.new_week?
|
35
35
|
end
|
36
36
|
|
37
37
|
if state.index == 2
|
38
|
-
assert_equal 2,
|
39
|
-
assert_equal 0,
|
38
|
+
assert_equal 2, match.score1
|
39
|
+
assert_equal 0, match.score2
|
40
40
|
assert_equal false, state.new_date?
|
41
41
|
assert_equal false, state.new_year?
|
42
42
|
assert_equal false, state.new_week?
|
43
43
|
end
|
44
44
|
|
45
45
|
if state.index == 3
|
46
|
-
assert_equal 3,
|
47
|
-
assert_equal 2,
|
46
|
+
assert_equal 3, match.score1
|
47
|
+
assert_equal 2, match.score2
|
48
48
|
assert_equal true, state.new_date?
|
49
49
|
assert_equal true, state.new_week?
|
50
50
|
assert_equal false, state.new_year?
|