oeffi 0.0.7 → 0.0.8
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 +4 -4
- data/lib/oeffi.rb +2 -2
- data/lib/oeffi/locations.rb +15 -1
- data/lib/oeffi/queries.rb +9 -2
- data/lib/oeffi/version.rb +1 -1
- data/oeffi.gemspec +2 -0
- data/spec/location_spec.rb +7 -0
- data/spec/oeffi_spec.rb +8 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a5861852dafeed82d4598d63240b3f45c3801a9
|
4
|
+
data.tar.gz: 1b39b7fc533929aff3ce3de6f45c32605ff4bdb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ecd37b3ab7c96796c429d0fb7d36db59ce57958b3f2c3c95ff06723956235836cde10a3ee08d13e4ea5f7cccbe2a0fddb07aa182242d115962867f2164b3c4f
|
7
|
+
data.tar.gz: c16e675f20c1219da2f45bbe76cccae57673009284a727264a2f8eed1685ee90eb6920b372ea62efb33a69a43fe36e11c19928dfa46facc64bcf7f012a8fb2d9
|
data/lib/oeffi.rb
CHANGED
@@ -13,8 +13,8 @@ module Oeffi
|
|
13
13
|
yield(configuration)
|
14
14
|
end
|
15
15
|
|
16
|
-
def autocomplete(string="")
|
17
|
-
Oeffi::AutocompleteQuery.new(string).perform
|
16
|
+
def autocomplete(string="", location={})
|
17
|
+
Oeffi::AutocompleteQuery.new(string, location[:lat], location[:lon]).perform
|
18
18
|
end
|
19
19
|
|
20
20
|
def find_trips(opts)
|
data/lib/oeffi/locations.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
java_import "de.schildbach.pte.dto.Location"
|
2
|
+
require "geokit"
|
3
|
+
require "pry"
|
2
4
|
|
3
5
|
module Locations
|
4
6
|
class Location
|
5
|
-
attr_accessor :id, :type, :name, :lat, :lon
|
7
|
+
attr_accessor :id, :type, :name, :lat, :lon, :loc
|
8
|
+
alias_method :distance_to!, :loc=
|
6
9
|
STATION = 0
|
7
10
|
ADDRESS = 1
|
8
11
|
POI = 2
|
@@ -21,7 +24,18 @@ module Locations
|
|
21
24
|
[:id, :type, :name, :lat, :lon].each do |sym|
|
22
25
|
hash[sym] = self.send sym
|
23
26
|
end
|
27
|
+
unless @lat.nil? or @loc.nil?
|
28
|
+
hash[:distance_to] = distance_to
|
29
|
+
end
|
24
30
|
return hash
|
25
31
|
end
|
32
|
+
|
33
|
+
def distance_to
|
34
|
+
return 0 unless @lat > 0 and @lon > 0
|
35
|
+
return 0 unless @loc[:lat] > 0 and @loc[:lon] > 0
|
36
|
+
from = Geokit::LatLng.new @lat, @lon
|
37
|
+
to = Geokit::LatLng.new loc[:lat], loc[:lon]
|
38
|
+
(from.distance_to to, unit: :km) * 1000
|
39
|
+
end
|
26
40
|
end
|
27
41
|
end
|
data/lib/oeffi/queries.rb
CHANGED
@@ -5,6 +5,7 @@ module Queries
|
|
5
5
|
include Locations
|
6
6
|
include Trips
|
7
7
|
class Query
|
8
|
+
attr :lat, :lon
|
8
9
|
def perform(method, args)
|
9
10
|
Oeffi.provider.send(method, *args)
|
10
11
|
end
|
@@ -12,14 +13,20 @@ module Queries
|
|
12
13
|
|
13
14
|
class AutocompleteQuery < Query
|
14
15
|
attr_accessor :string
|
15
|
-
def initialize(string)
|
16
|
+
def initialize(string, lat=nil, lon=nil)
|
16
17
|
@string = string
|
18
|
+
@lat = lat
|
19
|
+
@lon = lon
|
17
20
|
end
|
18
21
|
|
19
22
|
def perform
|
20
23
|
result = super :autocompleteStations, [@string]
|
21
24
|
result.to_a.map do |station|
|
22
|
-
Locations::Location.new(station)
|
25
|
+
location = Locations::Location.new(station)
|
26
|
+
unless @lat.nil? or @lon.nil?
|
27
|
+
location.distance_to!({lat: @lat, lon: @lon})
|
28
|
+
end
|
29
|
+
location.as_json
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
data/lib/oeffi/version.rb
CHANGED
data/oeffi.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "geokit"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
spec.add_development_dependency "rspec"
|
data/spec/location_spec.rb
CHANGED
@@ -11,4 +11,11 @@ describe Location do
|
|
11
11
|
|
12
12
|
result[:id].should equal 13000
|
13
13
|
end
|
14
|
+
|
15
|
+
it "should be able to tell the distance to a certain point" do
|
16
|
+
jLocation = Java::DeSchildbachPteDto::Location.new Java::DeSchildbachPteDto::LocationType::STATION, 51344352, 12380712
|
17
|
+
location = Locations::Location.new jLocation
|
18
|
+
location.distance_to!({lat: 51.3394580, :lon => 12.3745350})
|
19
|
+
location.distance_to.should be_within(100).of 500
|
20
|
+
end
|
14
21
|
end
|
data/spec/oeffi_spec.rb
CHANGED
@@ -37,6 +37,14 @@ describe "Oeffi module" do
|
|
37
37
|
station.should be_a Hash
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
it "should be able to tell the distance to a station when autocompleting" do
|
42
|
+
result = Oeffi::autocomplete("Leipzig", {:lat => 51.3394580, :lon => 12.3745350})
|
43
|
+
result.should be_an Array
|
44
|
+
result.each do |station|
|
45
|
+
station[:distance_to].should_not be_nil
|
46
|
+
end
|
47
|
+
end
|
40
48
|
end
|
41
49
|
|
42
50
|
describe "Trip finding" do
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oeffi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Kraft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: geokit
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
version_requirements: !ruby/object:Gem::Requirement
|