46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/parse_result.rb', line 46
def parse member, doc
doc.css('li').each_with_index do |li, i|
if li.text =~ /first name=(.*)/i && member.first_name.downcase != $1.downcase then
raise "first name #{$1} in results does not match #{member.first_name}"
end
if li.text =~ /last name=(.*)/i && member.last_name.downcase != $1.downcase then
raise "last name #{$1} in results does not match #{member.last_name}"
end
end
year_results = nil
doc.css('table table tr').each do |row|
result_data = row.css('td')
next if result_data.size.zero?
member.results<< Result.new({
:certificate => result_data[0].text,
:type => result_data[1].text,
:distance => result_data[2].text,
:date => Time.parse(result_data[3].text.gsub("-","/")),
:organizer => result_data[4].text,
} )
end
year_results = member.results.last.date.year unless member.results.empty?
member.awards[year_results] = [] unless year_results.nil? or member.awards.has_key? year_results
doc.css('table tr td').each do |row|
next unless row.text =~ /Award status: (.*)/i
$1.split(",").each do |award_type|
member.awards[year_results]<< Award.new({
:type => award_type.strip,
:year => year_results.to_i,
})
end
end
end
|