Class: LiveSoccer::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/live_soccer/checker.rb

Constant Summary collapse

MATCHES_URL =
"http://www.espn.com.br/old/temporeal/acoes.listaPartidasAjax.tiles.logic?"

Class Method Summary collapse

Class Method Details

.fetch_matchesObject



14
15
16
# File 'lib/live_soccer/checker.rb', line 14

def self.fetch_matches
  @fetch_matches ||= HTTParty.get(MATCHES_URL).parsed_response
end

.parse_matchesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/live_soccer/checker.rb', line 18

def self.parse_matches
  [].tap do |matches|
    self.each_match do |match|
      date = "#{match.soccer_value 'li.noticia_dia'} #{match.soccer_value 'li.noticia_hora'} -03:00"
      
      matches << { date: DateTime.parse(date), 
                   home: match.soccer_value('div.jogo td.time1'),
                   visitor: match.soccer_value('div.jogo td.time2'), 
                   score: match.css('div.jogo td.placar').last.content.strip,
                   id: match.css('div.jogo td.placar a').first && match.css('div.jogo td.placar a').first.attributes["href"].value.split("id=").last }
    end
  end
end