-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhershey_meet_data.rb
61 lines (49 loc) · 1.64 KB
/
hershey_meet_data.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'event'
require 'participant'
class HersheyMeetData
def initialize
@age_groups = {}
end
def add_participant(name, community, event, age_group, time_distance)
# create a hash if the age group doesn't exist
@age_groups[age_group] ||= {}
# get back the hash of events for the specific age group
age_group_events = @age_groups[age_group]
# create an array if the event doesn't exist
age_group_events[event] ||= []
participant_array = age_group_events[event]
# create an array that represents the participant for that age group and event
participant = Participant.new
participant.name = name
participant.community = community
participant.time_distance = time_distance
# add participant_info to the participant_array
participant_array << participant
end
def each_event_as_array
@age_groups.each do |age_group, event_hash|
event_hash.each_key do |event|
yield age_group, event, event_array(age_group, event)
end
end
end
private
def event_array(age_group, event)
results = []
age_group_events = @age_groups[age_group]
if age_group_events
if age_group_events.has_key?(event)
event_participants = age_group_events.fetch(event)
if Event.is_field_event?(event)
event_participants = Participant.field_event_sort(event_participants)
else
event_participants = Participant.running_event_sort(event_participants)
end
event_participants.each do |participant|
results << participant.create_array(event)
end
end
end
results.to_a
end
end