bikeshare 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/lib/bikeshare.rb +38 -43
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDVhZTYyNTljNjAzMGUwMWEwYjBiMDYwODljYTYyYzMwYTg1MjgwNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
YTM5MmJmZWIwN2QyM2JhNDlhZmNlNGI3NTRhZjk5Y2Y5N2FmMjNhZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTAzMDJhNDFlZmFlMmQxMmVkNTY3MmVjZmY0MGM5OTI2ZWY4ZmVlNTdmNDlj
|
10
|
+
NDRhOTcxOTFmOTg5YWIzYzVkNWNiNjM1NzQ5OWI2OWI5NjRiMzVlMjdmMmUz
|
11
|
+
MDNhZDYxZWU4YzE2MzkzNDVkMzM0YzQ2Zjk3ZmYwNzkwMGJlZWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Yzk1ZjUxYzQzZWExNjBkY2E0MTMyNjYzYjM0ZDY4ZTIzYmU5MWQyY2Q3NzMy
|
14
|
+
YmI4Njk4NjIxNDkwMTFlOTg0NmYzMDdiMzk5ZjhlMGIxNjU2MzI0NDQ3MWQ0
|
15
|
+
ZDU3YWFlZWFmYjgxMWU1ZjcyMzYyNGRmMmJjZTkzNDdkOWNlMTU=
|
data/lib/bikeshare.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class BikeShare
|
2
2
|
|
3
|
+
FIRST_STATION_ID = 2
|
4
|
+
|
3
5
|
def initialize
|
4
6
|
response = JSON.parse(open("http://bayareabikeshare.com/stations/json").read)
|
5
7
|
@response = response["stationBeanList"]
|
@@ -9,17 +11,11 @@ class BikeShare
|
|
9
11
|
@response.last["id"]
|
10
12
|
end
|
11
13
|
|
12
|
-
def between?(min, max)
|
13
|
-
(min >= 2 && max <= get_last_station) ? true : false
|
14
|
-
end
|
15
|
-
|
16
14
|
def station_info(station_id)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
raise "Please enter a station id in between 2 and #{last_station}"
|
22
|
-
end
|
15
|
+
check_valid_station_id!(station_id)
|
16
|
+
|
17
|
+
station = @response.select { |station| station["id"] == station_id }
|
18
|
+
station.first
|
23
19
|
end
|
24
20
|
|
25
21
|
def stations(*city_name)
|
@@ -37,56 +33,46 @@ class BikeShare
|
|
37
33
|
end
|
38
34
|
|
39
35
|
def empty?(station_id)
|
40
|
-
|
41
|
-
station = @response.select { |station| station["id"] == station_id }
|
36
|
+
check_valid_station_id!(station_id)
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
38
|
+
station = @response.select { |station| station["id"] == station_id }
|
39
|
+
|
40
|
+
station.first["availableBikes"] == 0 ? true : false
|
47
41
|
end
|
48
42
|
|
49
43
|
def full?(station_id)
|
50
|
-
|
51
|
-
station = @response.select { |station| station["id"] == station_id }
|
44
|
+
check_valid_station_id!(station_id)
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
46
|
+
station = @response.select { |station| station["id"] == station_id }
|
47
|
+
|
48
|
+
station.first["availableBikes"] == station.first["totalDocks"] ? true : false
|
57
49
|
end
|
58
50
|
|
59
51
|
def available_bikes(station_id)
|
60
|
-
|
61
|
-
station = @response.select { |station| station["id"] == station_id }
|
52
|
+
check_valid_station_id!(station_id)
|
62
53
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
54
|
+
station = @response.select { |station| station["id"] == station_id }
|
55
|
+
|
56
|
+
station.first["availableBikes"]
|
67
57
|
end
|
68
58
|
|
69
59
|
def total_docks(station_id)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
raise "Please enter a station id in between 2 and #{last_station}"
|
75
|
-
end
|
60
|
+
check_valid_station_id!(station_id)
|
61
|
+
|
62
|
+
station = @response.select { |station| station["id"] == station_id }
|
63
|
+
station.first["totalDocks"]
|
76
64
|
end
|
77
65
|
|
78
66
|
def percent_available(station_id)
|
79
|
-
|
80
|
-
station = @response.select { |station| station["id"] == station_id }
|
67
|
+
check_valid_station_id!(station_id)
|
81
68
|
|
82
|
-
|
83
|
-
total = (station.first["totalDocks"]).to_f
|
69
|
+
station = @response.select { |station| station["id"] == station_id }
|
84
70
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
available = (station.first["availableBikes"]).to_f
|
72
|
+
total = (station.first["totalDocks"]).to_f
|
73
|
+
|
74
|
+
percentage = (available * 100.0) / total
|
75
|
+
percentage.round(2)
|
90
76
|
end
|
91
77
|
|
92
78
|
def offline_stations
|
@@ -95,4 +81,13 @@ class BikeShare
|
|
95
81
|
list.empty? ? [] : list
|
96
82
|
end
|
97
83
|
|
84
|
+
private
|
85
|
+
|
86
|
+
def check_valid_station_id!(station_id)
|
87
|
+
first = FIRST_STATION_ID
|
88
|
+
last = get_last_station
|
89
|
+
|
90
|
+
raise "Please enter a station id in between #{first} and #{last}" unless station_id.between?(first, last)
|
91
|
+
end
|
92
|
+
|
98
93
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bikeshare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zack Shapiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Ditto
|
14
14
|
email: zack@zackshapiro.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
39
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
40
|
+
rubygems_version: 2.0.7
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: A Ruby wrapper for Bay Area Bike Share station information
|