class Performance
competitors have many contests through performances and vice versa
Attributes
competitor[RW]
contest[RW]
director[RW]
number_on_stage[RW]
place[RW]
score[RW]
year[RW]
Public Class Methods
all()
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 76 def self.all @@all end
champs_type_by_year(type)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 63 def self.champs_type_by_year(type) all.select { |p| p.place == 1 && p.contest.type = type }.sort_by { |p| p.year } end
clear()
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 80 def self.clear @@all.clear end
create(arg_hash)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 22 def self.create(arg_hash) performance = new(arg_hash) performance.save performance end
create_c_performance(c_champs_hash)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 37 def self.create_c_performance(c_champs_hash) performance = create(c_champs_hash) performance.competitor = Chorus.find_or_create(c_champs_hash) performance.competitor.performances << performance performance.contest = Contest.find_or_create(c_champs_hash) performance.contest.performances << performance performance end
create_performance(arg_hash, type)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 46 def self.create_performance(arg_hash, type) performance = create(arg_hash) performance.competitor = \ (type == "chorus" ? Chorus : Quartet).send :find_or_create, arg_hash performance.competitor.performances << performance performance.contest = Contest.find_or_create(arg_hash) performance.contest.performances << performance performance end
create_q_performance(q_champs_hash)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 28 def self.create_q_performance(q_champs_hash) performance = create(q_champs_hash) performance.competitor = Quartet.find_or_create(q_champs_hash) performance.competitor.performances << performance performance.contest = Contest.find_or_create(q_champs_hash) performance.contest.performances << performance performance end
filter_all(place: nil, year: nil, type: nil, comp_name: nil)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 67 def self.filter_all(place: nil, year: nil, type: nil, comp_name: nil) filter = self.all place && filter = filter.select { |p| p.place == place }.sort_by { |p| p.year.to_i } year && filter = filter.select { |p| p.year == year }.sort_by { |p| p.place.to_i } type && filter = filter.select { |p| p.competitor.type == type } comp_name && filter = filter.select { |p| p.competitor.name == name } filter end
find_or_create(arg_hash, type)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 56 def self.find_or_create(arg_hash, type) found = self.all.find do |p| p.year == arg_hash[:year] && p.competitor.name == arg_hash[:name] end found || create_performance(arg_hash, type) end
new(arg_hash)
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 7 def initialize(arg_hash) self.year = arg_hash[:year] self.score = arg_hash[:score] self.place = arg_hash[:place] # the following will generally be nil at this point self.contest = arg_hash[:contest] self.competitor = arg_hash[:competitor] self.number_on_stage = arg_hash[:number_on_stage] self.director = arg_hash[:director] end
Public Instance Methods
save()
click to toggle source
# File lib/barbershop_contestants/performance.rb, line 18 def save @@all << self end