Class: Performance
- Inherits:
-
Object
- Object
- Performance
- Defined in:
- lib/barbershop_contestants/performance.rb
Overview
competitors have many contests through performances and vice versa
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#competitor ⇒ Object
Returns the value of attribute competitor.
-
#contest ⇒ Object
Returns the value of attribute contest.
-
#director ⇒ Object
Returns the value of attribute director.
-
#number_on_stage ⇒ Object
Returns the value of attribute number_on_stage.
-
#place ⇒ Object
Returns the value of attribute place.
-
#score ⇒ Object
Returns the value of attribute score.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
- .all ⇒ Object
- .champs_type_by_year(type) ⇒ Object
- .clear ⇒ Object
- .create(arg_hash) ⇒ Object
- .create_c_performance(c_champs_hash) ⇒ Object
- .create_performance(arg_hash, type) ⇒ Object
- .create_q_performance(q_champs_hash) ⇒ Object
- .filter_all(place: nil, year: nil, type: nil, comp_name: nil) ⇒ Object
- .find_or_create(arg_hash, type) ⇒ Object
Instance Method Summary collapse
-
#initialize(arg_hash) ⇒ Performance
constructor
A new instance of Performance.
- #save ⇒ Object
Constructor Details
#initialize(arg_hash) ⇒ Performance
Returns a new instance of Performance.
7 8 9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#competitor ⇒ Object
Returns the value of attribute competitor.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def competitor @competitor end |
#contest ⇒ Object
Returns the value of attribute contest.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def contest @contest end |
#director ⇒ Object
Returns the value of attribute director.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def director @director end |
#number_on_stage ⇒ Object
Returns the value of attribute number_on_stage.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def number_on_stage @number_on_stage end |
#place ⇒ Object
Returns the value of attribute place.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def place @place end |
#score ⇒ Object
Returns the value of attribute score.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def score @score end |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/barbershop_contestants/performance.rb', line 3 def year @year end |
Class Method Details
.all ⇒ Object
76 77 78 |
# File 'lib/barbershop_contestants/performance.rb', line 76 def self.all @@all end |
.champs_type_by_year(type) ⇒ Object
63 64 65 |
# 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 ⇒ Object
80 81 82 |
# File 'lib/barbershop_contestants/performance.rb', line 80 def self.clear @@all.clear end |
.create(arg_hash) ⇒ Object
22 23 24 25 26 |
# 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) ⇒ Object
37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
67 68 69 70 71 72 73 74 |
# 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) ⇒ Object
56 57 58 59 60 61 |
# 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 |
Instance Method Details
#save ⇒ Object
18 19 20 |
# File 'lib/barbershop_contestants/performance.rb', line 18 def save @@all << self end |