Class: SciolyFF::Interpreter::Team

Inherits:
Model
  • Object
show all
Defined in:
lib/sciolyff/interpreter/team.rb

Overview

Models an instance of a Science Olympiad team at a specific tournament

Instance Attribute Summary collapse

Attributes inherited from Model

#tournament

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect

Constructor Details

This class inherits a constructor from SciolyFF::Interpreter::Model

Instance Attribute Details

#penaltiesObject (readonly)

Returns the value of attribute penalties.



18
19
20
# File 'lib/sciolyff/interpreter/team.rb', line 18

def penalties
  @penalties
end

#placingsObject (readonly)

Returns the value of attribute placings.



18
19
20
# File 'lib/sciolyff/interpreter/team.rb', line 18

def placings
  @placings
end

#subdivision_teamObject (readonly)

Returns the value of attribute subdivision_team.



18
19
20
# File 'lib/sciolyff/interpreter/team.rb', line 18

def subdivision_team
  @subdivision_team
end

Instance Method Details

#cityObject



48
49
50
# File 'lib/sciolyff/interpreter/team.rb', line 48

def city
  @rep[:city]
end

#disqualified?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/sciolyff/interpreter/team.rb', line 40

def disqualified?
  @rep[:disqualified] || false
end

#earned_bid?Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/sciolyff/interpreter/team.rb', line 68

def earned_bid?
  school_rank = @tournament.teams_eligible_for_bids.find_index(self)
  !school_rank.nil? && school_rank < @tournament.bids
end

#exhibition?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sciolyff/interpreter/team.rb', line 36

def exhibition?
  @rep[:exhibition] || false
end


8
9
10
11
12
13
14
15
16
# File 'lib/sciolyff/interpreter/team.rb', line 8

def link_to_other_models(interpreter)
  super
  @placings  = interpreter.placings .select { |p| p.team == self }
  @penalties = interpreter.penalties.select { |p| p.team == self }
  @placings_by_event =
    @placings.group_by(&:event).transform_values!(&:first)

  link_to_team_in_subdivision_interpreter(interpreter)
end

#medal_countsObject



87
88
89
90
91
92
# File 'lib/sciolyff/interpreter/team.rb', line 87

def medal_counts
  (1..@tournament.events.first.maximum_points).map do |medal_points|
    placings.select(&:considered_for_team_points?)
            .count { |p| p.points == medal_points }
  end
end

#numberObject



44
45
46
# File 'lib/sciolyff/interpreter/team.rb', line 44

def number
  @rep[:number]
end

#placing_for(event) ⇒ Object



56
57
58
# File 'lib/sciolyff/interpreter/team.rb', line 56

def placing_for(event)
  @placings_by_event[event]
end

#pointsObject



64
65
66
# File 'lib/sciolyff/interpreter/team.rb', line 64

def points
  @points ||= placings.sum(&:points) + penalties.sum(&:points)
end

#rankObject



60
61
62
# File 'lib/sciolyff/interpreter/team.rb', line 60

def rank
  @tournament.teams.find_index(self) + 1
end

#schoolObject



20
21
22
# File 'lib/sciolyff/interpreter/team.rb', line 20

def school
  @rep[:school]
end

#school_abbreviationObject



24
25
26
# File 'lib/sciolyff/interpreter/team.rb', line 24

def school_abbreviation
  @rep[:'school abbreviation']
end

#stateObject



52
53
54
# File 'lib/sciolyff/interpreter/team.rb', line 52

def state
  @rep[:state]
end

#subdivisionObject



32
33
34
# File 'lib/sciolyff/interpreter/team.rb', line 32

def subdivision
  @rep[:subdivision]
end

#suffixObject



28
29
30
# File 'lib/sciolyff/interpreter/team.rb', line 28

def suffix
  @rep[:suffix]
end

#trial_event_medal_countsObject



94
95
96
97
98
99
# File 'lib/sciolyff/interpreter/team.rb', line 94

def trial_event_medal_counts
  (1..@tournament.events.last.maximum_points).map do |medal_points|
    placings.select { |p| p.event.trial? }
            .count { |p| p.isolated_points == medal_points }
  end
end

#trial_event_pointsObject



83
84
85
# File 'lib/sciolyff/interpreter/team.rb', line 83

def trial_event_points
  placings.select { |p| p.event.trial? }.sum(&:isolated_points)
end

#worst_placings_to_be_droppedObject



73
74
75
76
77
78
79
80
81
# File 'lib/sciolyff/interpreter/team.rb', line 73

def worst_placings_to_be_dropped
  return [] if @tournament.worst_placings_dropped.zero?

  placings
    .select(&:initially_considered_for_team_points?)
    .sort_by(&:isolated_points)
    .reverse
    .take(@tournament.worst_placings_dropped)
end