bikeshare 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/bikeshare.rb +94 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWNjODliM2UwMzAzYmJkNTczM2E5MTE5YzYzNGZmNzk0MTgwNTQyYQ==
5
+ data.tar.gz: !binary |-
6
+ YzgyOTBiMDU1MTRkMWFkZjY4NjAwNmQ5NjlhOThlYTNiMTc1MWQ3MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjQ0YzUxMGMxY2FhOGFjYjY1YjJiMjc1ZWM1NWM4YjM3Njc5MjgyOTRlNWQy
10
+ NGEzY2ZkMmVkNDllMmFiODAyNTQ4YWQ1MWVkMWYwMmVlMmJjZTY1MGM3N2Ez
11
+ MWM3NmY3M2YyZDE1ODZiNDgyZjFlMmVkOTQzMzM2YmMxYmYxYmM=
12
+ data.tar.gz: !binary |-
13
+ MGFiNzU0Nzg5NzcwYTZkMjFmZTI4YjU1MDBhODdkN2UxZGU1YTQ3YTlkZmUy
14
+ MmI1NDk0MmU5NWEzYTc4YmIzY2ZiNTM2YTkzOGMyMWNmZDJhYzFjNWY0Yzk0
15
+ YTZiNWQ0NTM1ODg4MzQxMGQ1NTU3OTZiOWU4OWM1Zjk3YWI0NmY=
data/lib/bikeshare.rb ADDED
@@ -0,0 +1,94 @@
1
+ class BikeShare
2
+
3
+ def initialize
4
+ response = JSON.parse(open("http://bayareabikeshare.com/stations/json").read)
5
+ @response = response["stationBeanList"]
6
+ end
7
+
8
+ def get_last_station
9
+ @response.last["id"]
10
+ end
11
+
12
+ def station_info(station_id)
13
+ last_station = get_last_station
14
+
15
+ if station_id >= 2 && station_id <= last_station
16
+ station = @response.select { |station| station["id"] == station_id }
17
+ station.first
18
+ else
19
+ raise "Please enter a station id in between 2 and #{last_station}"
20
+ end
21
+
22
+ end
23
+
24
+ def stations(*city_name)
25
+ city_name = city_name.first
26
+
27
+ if city_name.nil?
28
+ stations = @response
29
+ else
30
+ stations = @response.select { |station| station["landMark"] == "#{city_name}" }
31
+ end
32
+ end
33
+
34
+ def empty_stations
35
+ @response.select { |station| station["availableBikes"] == 0 }
36
+ end
37
+
38
+ def empty?(station_id)
39
+ last_station = get_last_station
40
+
41
+ if station_id >= 2 && station_id <= last_station
42
+ station = @response.select { |station| station["id"] == station_id }
43
+
44
+ station.first["availableBikes"] == 0 ? true : false
45
+ else
46
+ raise "Please enter a station id in between 2 and #{last_station}"
47
+ end
48
+ end
49
+
50
+ def available_bikes(station_id)
51
+ last_station = get_last_station
52
+
53
+ if station_id >= 2 && station_id <= last_station
54
+ station = @response.select { |station| station["id"] == station_id }
55
+ station.first["availableBikes"]
56
+ else
57
+ raise "Please enter a station id in between 2 and #{last_station}"
58
+ end
59
+ end
60
+
61
+ def total_docks(station_id)
62
+ last_station = get_last_station
63
+
64
+ if station_id >= 2 && station_id <= last_station
65
+ station = @response.select { |station| station["id"] == station_id }
66
+ station.first["totalDocks"]
67
+ else
68
+ raise "Please enter a station id in between 2 and #{last_station}"
69
+ end
70
+ end
71
+
72
+ def percent_available(station_id)
73
+ last_station = get_last_station
74
+
75
+ if station_id >= 2 && station_id <= last_station
76
+ station = @response.select { |station| station["id"] == station_id }
77
+
78
+ available = (station.first["availableBikes"]).to_f
79
+ total = (station.first["totalDocks"]).to_f
80
+
81
+ percentage = (available * 100.0) / total
82
+ percentage.round(2)
83
+ else
84
+ raise "Please enter a station id in between 2 and #{last_station}"
85
+ end
86
+ end
87
+
88
+ def offline_stations
89
+ list = @response.select { |station| station["statusKey"] == 0 }
90
+
91
+ list.empty? ? [] : list
92
+ end
93
+
94
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bikeshare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Zack Shapiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ditto
14
+ email: zack@zackshapiro.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/bikeshare.rb
20
+ homepage: https://github.com/zackshapiro/bay-area-bike-share
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.1.5
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A Ruby wrapper for Bay Area Bike Share station information
44
+ test_files: []