Class: SodaXmlTeam::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/soda_xml_team/schedule.rb

Class Method Summary collapse

Class Method Details

.parse_schedule(document = {}) ⇒ Object



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
# File 'lib/soda_xml_team/schedule.rb', line 7

def self.parse_schedule(document={})

  output = []

  unless document.is_a? Nokogiri::XML::Document
    raise "Invalid XML schedule."
  end

  document.css('schedule sports-event').each do |event|

    row = {}

    event.css('event-metadata').each do |eventmeta|
      row[:event_key] = eventmeta['event-key']
      row[:start_date_time] = eventmeta['start-date-time']
    end
    event.css('team team-metadata[alignment="away"]').each do |away_team|
      team_name = away_team.css('name').first
      row[:away_team_id] = away_team['team-key']
      row[:away_team] = "#{team_name['first']} #{team_name['last']}"
    end
    event.css('team team-metadata[alignment="home"]').each do |home_team|
      team_name = home_team.css('name').first
      row[:home_team_id] = home_team['team-key']
      row[:home_team] = "#{team_name['first']} #{team_name['last']}"
    end
    output << row
  end

  return output

end