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://www.cetsp.com.br/"
- VERSION =
"0.0.2"
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 |
# File 'lib/traffic-scraper.rb', line 13 def overall_traffic zone_traffic.values.inject(:+) rescue raise CouldNotRetrievePageError end |
.zone_traffic ⇒ Hash
Returns the amount of overall traffic we currently have
22 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 22 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| match = /^(\d+)\s*km$/.match(page.css(".info.#{zone} h4").inner_html) raise CouldNotRetrievePageError unless match result_hash[zone_translation] = match[1].to_i end result_hash rescue raise CouldNotRetrievePageError end |