mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-07 14:57:48 +00:00
Persisting matchups
This commit is contained in:
@@ -4,18 +4,19 @@ class Tournament < ActiveRecord::Base
|
|||||||
has_many :matches, dependent: :destroy
|
has_many :matches, dependent: :destroy
|
||||||
has_many :mats, dependent: :destroy
|
has_many :mats, dependent: :destroy
|
||||||
attr_accessor :upcomingMatches, :unfinishedMatches
|
attr_accessor :upcomingMatches, :unfinishedMatches
|
||||||
|
serialize :matchups, Array
|
||||||
|
|
||||||
def unfinishedMatches
|
def unfinishedMatches
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
@matches = []
|
if self.matchups?
|
||||||
self.weights.sort_by{|x|[x.max]}.each do |weight|
|
return self.matchups
|
||||||
@upcomingMatches = weight.generateMatchups(@matches)
|
else
|
||||||
|
@upcomingMatches = generateMatchups
|
||||||
|
return @upcomingMatches
|
||||||
end
|
end
|
||||||
@upcomingMatches = assignBouts(@upcomingMatches)
|
|
||||||
return @upcomingMatches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -26,7 +27,16 @@ class Tournament < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generateMatchups
|
||||||
|
@matches = []
|
||||||
|
self.weights.map.sort_by{|x|[x.max]}.each do |weight|
|
||||||
|
@upcomingMatches = weight.generateMatchups(@matches)
|
||||||
|
end
|
||||||
|
@upcomingMatches = assignBouts(@upcomingMatches)
|
||||||
|
self.matchups = @upcomingMatches
|
||||||
|
self.save
|
||||||
|
return @upcomingMatches
|
||||||
|
end
|
||||||
|
|
||||||
def assignBouts(matches)
|
def assignBouts(matches)
|
||||||
@bouts = Bout.new
|
@bouts = Bout.new
|
||||||
|
|||||||
5
db/migrate/20150324233726_add_matchups_to_tournament.rb
Normal file
5
db/migrate/20150324233726_add_matchups_to_tournament.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class AddMatchupsToTournament < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :tournaments, :matchups, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150317122709) do
|
ActiveRecord::Schema.define(version: 20150324233726) do
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
t.integer "r_id"
|
t.integer "r_id"
|
||||||
@@ -51,6 +51,7 @@ ActiveRecord::Schema.define(version: 20150317122709) do
|
|||||||
t.string "director_email"
|
t.string "director_email"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.text "matchups"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user