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
|
# File 'lib/api.rb', line 11
def self.scrape_fights(array_of_events)
array_of_events.each do |event|
doc = Nokogiri::HTML(open("http://ufc-data-api.ufc.com/api/v1/us/events/#{event.id}"))
doc.css('.flipcard-front-pre').each do |card|
red_name = card.css('.fighter-name-red').text.strip
blue_name = card.css('.fighter-name-blue').text.strip
fight_stats = card.css('.fight-card-match-up td').map {|stat| stat.text}.select {|stat| stat != stat.empty?}
fight_hash = {}
fight_hash[:red_record] = fight_stats.first
fight_hash[:blue_record] = fight_stats[2]
fight_hash[:red_height] = fight_stats[3]
fight_hash[:blue_height] = fight_stats[5]
fight_hash[:red_weight] = fight_stats[6]
fight_hash[:blue_weight] = fight_stats[8]
new_fight = Concerns::EventFight.new(red_name, blue_name, fight_hash)
event.event_fights << new_fight
end
end
end
|