Module: BicingBCN

Defined in:
lib/bicingbcn.rb

Overview

BicingBCN is a simple module to interface Barcelona Bicing services:

For now it only retrieves bikes occupations.

Defined Under Namespace

Classes: Error

Constant Summary collapse

MAP_URI =
"http://www.bicing.com/localizaciones/localizaciones.php"

Class Method Summary collapse

Class Method Details

.occupations(options = {}) ⇒ Object

Get hash containing information about Bicing stations.

Options:

:map_uri: URI to map containing ML info

>> BicingBCN.occupations
=> {
     1 => {
      :bikes_available => 2,
      :bikes_total => 21,
      :coordinate_latitude => 41.397978,
      :coordinate_longitude => 2.180019,
      :name => "Gran Via de les Corts Catalanes 760",
     },
  ...
  ...
  }


50
51
52
53
54
55
# File 'lib/bicingbcn.rb', line 50

def self.occupations(options = {})
  map_uri = File.join(options[:map_uri] || MAP_URI) 
  htmldata = open(map_uri).read
  kmldata = htmldata.match(/exml.parseString\('(.*)'\);/)[1]
  self.process_kml(kmldata)
end