Class: Traffic::Scraper
- Inherits:
-
Object
- Object
- Traffic::Scraper
- 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
-
.overall_traffic ⇒ Integer
Returns the amount of overall traffic we currently have.
-
.zone_traffic ⇒ Hash
Returns the amount of overall traffic we currently have.
Class Method Details
.overall_traffic ⇒ Integer
Returns the amount of overall traffic we currently have
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_traffic ⇒ Hash
Returns the amount of overall traffic we currently have
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 |