velov 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c6bc25fdb5e560786d2f9897ae3d0b4f2797b5f
4
- data.tar.gz: a21d8265d840598cc3fbc751d2a1d22991ffa32b
3
+ metadata.gz: e04bf3b600753953de4df6992806321b511dbb07
4
+ data.tar.gz: ef3254e0cd9e2e89570536abc905dff865f6b362
5
5
  SHA512:
6
- metadata.gz: 0b025bbda3f01363f26e3d6c50929857c05fcedd2865a86a2fc6102cc888a27598cc67d9e1d674bb283d2aee4a5621825738f3b6d6a0ff9027a294ce8fabd6c0
7
- data.tar.gz: 956418df4e0ed3e2766f77b1c1e0ec1fd37087bafc39013acfba2bb93cc211f03e5c773efacf174e86f8f8987c0ad8296202eca6291e7404bc47c1de6fc20f21
6
+ metadata.gz: 375040c3f68d210b23fd7a0b10c7104fb4651dcd23f0e42a5901a3c69a1f9c2b3ef67cf242f9e5847f3bf6b456631c44baed21dbb01f73ac3f942376eafca250
7
+ data.tar.gz: b88e547a1753f94d7eed89667c1d05100cc57e75e6fd299c51bea1b7f6d550d43842e2eba8df16622a1c7cf4d699d6f0fe6a7870b98248b112a523e0053dd37a
data/README.md CHANGED
@@ -18,7 +18,21 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ### Retrieve all stations
22
+ You can fetch data of all stations in one call:
23
+
24
+ station_list = Velov::StationList.fetch
25
+
26
+ Use an array to navigate through the data:
27
+
28
+ total_available_bikes = station_list.to_a.map(&:available_bikes).inject(:+)
29
+
30
+ ### Play with one station
31
+ You can find a specific station with its ID:
32
+
33
+ station = Velov::Station.find_by_number(10117)
34
+ station.lat
35
+ station.lng
22
36
 
23
37
  ## Contributing
24
38
 
data/lib/velov/station.rb CHANGED
@@ -36,5 +36,9 @@ module Velov
36
36
  # nil if not found
37
37
  StationList.fetch({ "field" => "number", "value" => number}).to_a.first
38
38
  end
39
+
40
+ def distance_to(lat,lng)
41
+ Geocoder::Calculations.distance_between([@lat,@lng], [lat,lng])
42
+ end
39
43
  end
40
44
  end
@@ -32,5 +32,23 @@ module Velov
32
32
  station_list
33
33
  end
34
34
 
35
+ def nearest(lat,lng)
36
+ @list.sort_by do |station|
37
+ station.distance_to(lat,lng)
38
+ end
39
+ end
40
+
41
+ def bike_stands
42
+ @list.map(&:bike_stands).inject(:+)
43
+ end
44
+
45
+ def available_bike_stands
46
+ @list.map(&:available_bike_stands).inject(:+)
47
+ end
48
+
49
+ def available_bikes
50
+ @list.map(&:available_bikes).inject(:+)
51
+ end
52
+
35
53
  end
36
54
  end
data/lib/velov/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Velov
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/velov.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'virtus'
2
2
  require 'faraday'
3
3
  require 'faraday_middleware'
4
+ require 'geocoder'
4
5
  require "velov/version"
5
6
  require "velov/api"
6
7
  require "velov/station"
@@ -1,13 +1,24 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Velov::StationList do
4
- describe ":fetch" do
5
- before(:each) do
6
- VCR.use_cassette "fetch_valid_station_list" do
7
- @station_list = Velov::StationList.fetch
8
- end
4
+ before(:each) do
5
+ VCR.use_cassette "fetch_valid_station_list" do
6
+ @station_list = Velov::StationList.fetch
9
7
  end
8
+ end
9
+ describe ":fetch" do
10
+
10
11
  it { expect(@station_list.size).to eq 349 }
11
12
  it { expect(@station_list.to_a.length).to eq 349}
12
13
  end
14
+
15
+ describe ":nearest" do
16
+ it { expect(@station_list.nearest(45.764563,4.892333).first.number).to eq 10117 }
17
+ end
18
+
19
+ describe "sums" do
20
+ it { expect(@station_list.bike_stands).to eq 6832}
21
+ it { expect(@station_list.available_bike_stands).to eq 3544}
22
+ it { expect(@station_list.available_bikes).to eq 3031}
23
+ end
13
24
  end
data/spec/station_spec.rb CHANGED
@@ -35,4 +35,14 @@ describe Velov::Station do
35
35
  it { expect(@station).to be nil}
36
36
  end
37
37
  end
38
+
39
+ describe ':distance_to' do
40
+ before(:each) do
41
+ VCR.use_cassette "find_valid_station_by_number" do
42
+ @station = Velov::Station.find_by_number(10117)
43
+ end
44
+ end
45
+
46
+ it { expect(@station.distance_to(45.8,4.9)).to eq 2.4761240501617032 }
47
+ end
38
48
  end
data/velov.gemspec CHANGED
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_runtime_dependency "faraday", '~> 0.9'
28
28
  spec.add_runtime_dependency "faraday_middleware", '~> 0.9'
29
- spec.add_runtime_dependency "virtus", '~> 1.0'
29
+ spec.add_runtime_dependency "virtus",'~> 1.0'
30
+ spec.add_runtime_dependency "geocoder", '~> 1.2'
30
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: velov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Baptiste Béchu
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: geocoder
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.2'
125
139
  description: This Wrapper allows you to play with objects like bike's stations ! It's
126
140
  possible to add more features, like "nearest station around me".
127
141
  email: