Class: Traffic::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/traffic-scraper.rb,
lib/traffic-scraper/version.rb

Constant Summary collapse

TRAFFIC_PAGE_URL =
"http://cetsp1.cetsp.com.br/monitransmapa/agora/"
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.overall_trafficInteger

Returns the amount of overall traffic we currently have

Returns:

  • (Integer)

    the amount of traffic



13
14
15
16
17
18
# File 'lib/traffic-scraper.rb', line 13

def overall_traffic
  page = Nokogiri::HTML(open(TRAFFIC_PAGE_URL))
  page.css("#lentidao b").inner_html.to_i
rescue
  raise CouldNotRetrievePageError
end

.zone_trafficHash

Returns the amount of overall traffic we currently have

Returns:

  • (Hash)

    containing all the traffic information for all zones



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/traffic-scraper.rb', line 23

def zone_traffic
  page = Nokogiri::HTML(open(TRAFFIC_PAGE_URL))

  result_hash = {}

  { "Norte" => :north ,
    "Sul" => :south,
    "Leste" => :east,
    "Oeste" => :west,
    "Centro" => :downtown
  }.each do |zone, zone_translation|
    page.css("##{zone}Lentidao").inner_html =~ /^(\d+)\s*km$/

    result_hash[zone_translation] = $1.to_i
  end

  result_hash
rescue
  raise CouldNotRetrievePageError
end