locomotion 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/locomotion/version.rb +1 -1
- data/motion/locomotion.rb +15 -0
- data/motion/locomotion/location.rb +4 -0
- data/motion/locomotion/watchman.rb +16 -0
- data/spec/locomotion/location_spec.rb +42 -0
- data/spec/locomotion/watchman_spec.rb +23 -17
- data/spec/support/fake_location_manager.rb +33 -0
- metadata +6 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0fe2c6c62bc55a832a7f7bed5545478b482a452
|
4
|
+
data.tar.gz: 3d395b4d55710a58b21f66644cb7f1c2200f8fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eea17a90db739eb0b6d4be28317baecc28d1a4a64a0b47abdd29a97a1575af2b0e295e39a8334ce31d954fc01c0793cb9b1ece70a01ac6ed18d81239fa4bd22
|
7
|
+
data.tar.gz: 2480e3a90d553128e90ea053525de21222e3855a77ce891af217ade4268838a59f9f0d398ed461d59ff28ed3bf04c768a5135e5708b2ffd0a843a558dbeb4472
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/locomotion/version.rb
CHANGED
data/motion/locomotion.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
module Locomotion
|
2
2
|
class << self
|
3
3
|
|
4
|
+
def accuracy= level
|
5
|
+
watchman.switch_to_accuracy({
|
6
|
+
best_for_navigation: KCLLocationAccuracyBestForNavigation,
|
7
|
+
best: KCLLocationAccuracyBest,
|
8
|
+
nearest_ten: KCLLocationAccuracyNearestTenMeters,
|
9
|
+
nearest_hundred: KCLLocationAccuracyHundredMeters,
|
10
|
+
nearest_km: KCLLocationAccuracyKilometer,
|
11
|
+
nearest_3km: KCLLocationAccuracyThreeKilometers
|
12
|
+
}.fetch(level, KCLLocationAccuracyBest))
|
13
|
+
end
|
14
|
+
|
15
|
+
def distance_filter= distance
|
16
|
+
watchman.switch_to_distance_filter distance || KCLDistanceFilterNone
|
17
|
+
end
|
18
|
+
|
4
19
|
def watch opts = {}, &block
|
5
20
|
watchman.process opts
|
6
21
|
watchman.listeners << block
|
@@ -30,6 +30,10 @@ module Locomotion
|
|
30
30
|
@original.horizontalAccuracy
|
31
31
|
end
|
32
32
|
|
33
|
+
def distance_to other
|
34
|
+
@original.distanceFromLocation CLLocation.alloc.initWithLatitude other.latitude, longitude: other.longitude
|
35
|
+
end
|
36
|
+
|
33
37
|
def inspect
|
34
38
|
"<Location #{latitude} #{longitude} >"
|
35
39
|
end
|
@@ -28,7 +28,13 @@ module Locomotion
|
|
28
28
|
@location_manager.allowDeferredLocationUpdatesUntilTraveled 10000, timeout: time
|
29
29
|
end
|
30
30
|
|
31
|
+
def reset
|
32
|
+
@location_manager.stopUpdatingLocation
|
33
|
+
@location_manager.startUpdatingLocation
|
34
|
+
end
|
35
|
+
|
31
36
|
def clear
|
37
|
+
@listeners = []
|
32
38
|
@location_manager.stopUpdatingLocation
|
33
39
|
end
|
34
40
|
|
@@ -41,5 +47,15 @@ module Locomotion
|
|
41
47
|
def error code
|
42
48
|
end
|
43
49
|
|
50
|
+
def switch_to_accuracy accuracy
|
51
|
+
@location_manager.desiredAccuracy = accuracy
|
52
|
+
reset
|
53
|
+
end
|
54
|
+
|
55
|
+
def switch_to_distance_filter distance
|
56
|
+
@location_manager.distanceFilter = distance
|
57
|
+
reset
|
58
|
+
end
|
59
|
+
|
44
60
|
end
|
45
61
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
describe 'location' do
|
2
|
+
before do
|
3
|
+
@cllocation = CLLocation.alloc.initWithCoordinate CLLocationCoordinate2D.new(1,2),
|
4
|
+
altitude: 10,
|
5
|
+
horizontalAccuracy: 4,
|
6
|
+
verticalAccuracy: 3,
|
7
|
+
course: 1.3,
|
8
|
+
speed: 1.5,
|
9
|
+
timestamp: Time.at(123456789)
|
10
|
+
@location = Locomotion::Location.alloc.init @cllocation
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'exposes latitude' do
|
14
|
+
@location.latitude.should.equal 1
|
15
|
+
end
|
16
|
+
it 'exposes longitude' do
|
17
|
+
@location.longitude.should.equal 2
|
18
|
+
end
|
19
|
+
it 'exposes speed' do
|
20
|
+
@location.speed.should.equal 1.5
|
21
|
+
end
|
22
|
+
it 'exposes heading' do
|
23
|
+
@location.heading.should.equal 1.3
|
24
|
+
end
|
25
|
+
it 'exposes time' do
|
26
|
+
@location.time.should.equal Time.at(123456789)
|
27
|
+
end
|
28
|
+
it 'exposes accuracy' do
|
29
|
+
@location.accuracy.should.equal 4
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'formats nicely' do
|
33
|
+
@location.to_s.should.equal "<Location 1.0 2.0 >"
|
34
|
+
@location.to_s.should.equal @location.inspect
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can calculate distance to another location' do
|
38
|
+
another_location = Locomotion::Location.alloc.init CLLocation.alloc.initWithLatitude 1, longitude: 3
|
39
|
+
@location.distance_to(another_location).should.be.close 111302.649, 0.001
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -1,31 +1,18 @@
|
|
1
1
|
describe 'the watchman' do
|
2
2
|
|
3
3
|
before do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def startUpdatingLocation
|
8
|
-
commands << :start
|
9
|
-
end
|
10
|
-
def stopUpdatingLocation
|
11
|
-
commands << :stop
|
12
|
-
end
|
13
|
-
def allowDeferredLocationUpdatesUntilTraveled distance, timeout: time
|
14
|
-
commands << [:defer,distance,time]
|
15
|
-
end
|
16
|
-
def commands
|
17
|
-
@commands ||= []
|
18
|
-
end
|
19
|
-
end
|
20
|
-
@watchman = Locomotion::Watchman.alloc.init test_manager
|
4
|
+
@watchman = Locomotion::Watchman.alloc.init FakeLocationManager
|
5
|
+
@watchman.location_manager.reset
|
21
6
|
end
|
22
7
|
|
23
8
|
it 'initialises the location manager with the minimum distance filter' do
|
24
9
|
@watchman.location_manager.distanceFilter.should.equal KCLDistanceFilterNone
|
25
10
|
end
|
11
|
+
|
26
12
|
it 'initialises the location manager with the best accuracy' do
|
27
13
|
@watchman.location_manager.desiredAccuracy.should.equal KCLLocationAccuracyBest
|
28
14
|
end
|
15
|
+
|
29
16
|
it 'sets the delegate to be a locomotion delegate' do
|
30
17
|
@watchman.location_manager.should.satisfy do |lm|
|
31
18
|
lm.delegate.class == Locomotion::Delegate and
|
@@ -47,19 +34,38 @@ describe 'the watchman' do
|
|
47
34
|
@watchman.go
|
48
35
|
@watchman.location_manager.commands.should.equal [:start]
|
49
36
|
end
|
37
|
+
|
50
38
|
it 'tells location manager to defer on pause' do
|
51
39
|
@watchman.pause 42
|
52
40
|
@watchman.location_manager.commands.should.equal [[:defer,10000,42]]
|
53
41
|
end
|
42
|
+
|
43
|
+
it 'tells location manager to stop then start on reset' do
|
44
|
+
@watchman.reset
|
45
|
+
@watchman.location_manager.commands.should.equal [:stop,:start]
|
46
|
+
end
|
47
|
+
|
54
48
|
it 'tells location manager to stop on clear' do
|
55
49
|
@watchman.clear
|
56
50
|
@watchman.location_manager.commands.should.equal [:stop]
|
57
51
|
end
|
58
52
|
|
53
|
+
it 'removes listeners on clear' do
|
54
|
+
@watchman.listeners << :a
|
55
|
+
@watchman.clear
|
56
|
+
@watchman.listeners.should.equal []
|
57
|
+
end
|
58
|
+
|
59
59
|
it 'tells listeners on update' do
|
60
60
|
@watchman.listeners << proc { |location| @location = location }
|
61
61
|
@watchman.update CLLocation.alloc.initWithLatitude 1, longitude: 1
|
62
62
|
@location.should.satisfy { |l| l.latitude == 1 && l.longitude == 1 }
|
63
63
|
end
|
64
64
|
|
65
|
+
{ switch_to_accuracy: :desiredAccuracy, switch_to_distance_filter: :distanceFilter }.each do |method,setting|
|
66
|
+
it "can configure #{setting} but resets afterwards" do
|
67
|
+
@watchman.send(method,42)
|
68
|
+
@watchman.location_manager.commands.should.equal [[setting,42],:stop,:start]
|
69
|
+
end
|
70
|
+
end
|
65
71
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class FakeLocationManager
|
2
|
+
attr_accessor :delegate, :distanceFilter, :desiredAccuracy, :purpose
|
3
|
+
|
4
|
+
def distanceFilter= value
|
5
|
+
commands << [:distanceFilter,value]
|
6
|
+
@distanceFilter = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def desiredAccuracy= value
|
10
|
+
commands << [:desiredAccuracy,value]
|
11
|
+
@desiredAccuracy= value
|
12
|
+
end
|
13
|
+
|
14
|
+
def startUpdatingLocation
|
15
|
+
commands << :start
|
16
|
+
end
|
17
|
+
|
18
|
+
def stopUpdatingLocation
|
19
|
+
commands << :stop
|
20
|
+
end
|
21
|
+
|
22
|
+
def allowDeferredLocationUpdatesUntilTraveled distance, timeout: time
|
23
|
+
commands << [:defer,distance,time]
|
24
|
+
end
|
25
|
+
|
26
|
+
def commands
|
27
|
+
@commands ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@commands = []
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rowe
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
2feWfO4gCNmvfFjULOAYHq9JHEjN5SLSXvj5HdSnDcCyIfJKn5Ya3JahWQaWIsXf
|
30
30
|
/NPE/mB57TOwj+d7XUa2NC4HUadF8R51IYEcIB0PpIEzJlKtfXFcOZxO
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-05-
|
32
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: bundler
|
@@ -81,7 +81,9 @@ files:
|
|
81
81
|
- motion/locomotion/watchman.rb
|
82
82
|
- spec/integration_spec.rb
|
83
83
|
- spec/locomotion/delegate_spec.rb
|
84
|
+
- spec/locomotion/location_spec.rb
|
84
85
|
- spec/locomotion/watchman_spec.rb
|
86
|
+
- spec/support/fake_location_manager.rb
|
85
87
|
homepage: https://github.com/JonRowe/locomotion
|
86
88
|
licenses:
|
87
89
|
- MIT
|
@@ -110,4 +112,6 @@ test_files:
|
|
110
112
|
- app/app_delegate.rb
|
111
113
|
- spec/integration_spec.rb
|
112
114
|
- spec/locomotion/delegate_spec.rb
|
115
|
+
- spec/locomotion/location_spec.rb
|
113
116
|
- spec/locomotion/watchman_spec.rb
|
117
|
+
- spec/support/fake_location_manager.rb
|
metadata.gz.sig
CHANGED
Binary file
|