Class: Kekka

Inherits:
Hash
  • Object
show all
Defined in:
lib/kekka/kekka.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(string_or_io) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kekka/kekka.rb', line 4

def self.parse string_or_io
  document = Nokogiri.parse string_or_io
  result = Kekka.new

  result[:persons] = hash_from document, 'person'
  result[:boats] = hash_from document, 'boat'
  result[:teams] = hash_from document, 'team' do  |team_hash, node|
    team_hash[:crew] = array_from node, 'crew'
  end
  result[:events] = hash_from document, 'event' do |event_hash, node|
    event_hash[:races]     = hash_from node, 'race'
    event_hash[:divisions] = hash_from node, 'division' do |division_hash, node|
      division_hash[:raceresults] = array_from node, 'raceresult' do |hash, node|
        team = result[:teams][hash['teamid']]
        hash['boatid'] = team['boatid']
      end
      division_hash[:seriesresults] = array_from node, 'seriesresult'
    end
  end

  result.update_boats_with_class

  result
end

Instance Method Details

#update_boats_with_classObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kekka/kekka.rb', line 29

def update_boats_with_class
  self[:events].each do |_, event|
    event[:divisions].each do |_, division|
      boat_class = division['title']
      division[:raceresults].each do |one_result|
        team = self[:teams][one_result['teamid']]
        boat = self[:boats][team['boatid']]
        boat['boatclass'] = boat_class
      end
    end
  end
end