Class: Locman::Manager
- Inherits:
-
Object
- Object
- Locman::Manager
- Defined in:
- lib/locman/manager.rb
Overview
This wraps CLLocationManager in more Ruby way.
Instance Attribute Summary collapse
-
#accuracy ⇒ Symbol
Desired accuracy of the location data.
-
#background ⇒ Boolean
Set whether location should be updated in the background or not.
-
#distance_filter ⇒ Integer
The minimum horizontal distance threshold for on_update event.
-
#on_error ⇒ Proc
Proc function that will be called when there is an error while retrieving the location.
-
#on_update ⇒ Proc
Proc function that will be called when there is a new location retrieval.
-
#on_visit ⇒ Proc
Proc function that will be called when there is a new visit event.
Instance Method Summary collapse
- #after_authorize=(after_authorize) ⇒ Object
- #authorize! ⇒ Object
- #authorized?(status = nil) ⇒ Boolean
-
#initialize(params = {}) ⇒ Locman::Manager
constructor
Creates a new Locman::Location instance.
-
#locationManager(manager, didVisit: cl_visit) ⇒ Object
Delegates.
- #stop_update! ⇒ Object
- #stop_update_significant! ⇒ Object
- #stop_update_visits! ⇒ Object
- #update! ⇒ Object
- #update_significant! ⇒ Object
- #update_visits! ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Locman::Manager
Creates a new Locman::Location instance.
49 50 51 52 53 54 55 56 |
# File 'lib/locman/manager.rb', line 49 def initialize(params = {}) params.each { |key, value| send("#{key}=", value) } @accuracy ||= :best @distance_filter ||= 0 self end |
Instance Attribute Details
#accuracy ⇒ Symbol
Returns Desired accuracy of the location data.
5 6 7 |
# File 'lib/locman/manager.rb', line 5 def accuracy @accuracy end |
#background ⇒ Boolean
Returns Set whether location should be updated in the background or not.
11 12 13 |
# File 'lib/locman/manager.rb', line 11 def background @background end |
#distance_filter ⇒ Integer
Returns The minimum horizontal distance threshold for on_update event.
8 9 10 |
# File 'lib/locman/manager.rb', line 8 def distance_filter @distance_filter end |
#on_error ⇒ Proc
Returns Proc function that will be called when there is an error while retrieving the location.
17 18 19 |
# File 'lib/locman/manager.rb', line 17 def on_error @on_error end |
#on_update ⇒ Proc
Returns Proc function that will be called when there is a new location retrieval.
14 15 16 |
# File 'lib/locman/manager.rb', line 14 def on_update @on_update end |
#on_visit ⇒ Proc
Returns Proc function that will be called when there is a new visit event.
20 21 22 |
# File 'lib/locman/manager.rb', line 20 def on_visit @on_visit end |
Instance Method Details
#after_authorize=(after_authorize) ⇒ Object
82 83 84 85 |
# File 'lib/locman/manager.rb', line 82 def () fail(ArgumentError, "Must provide proc") unless .is_a?(Proc) = end |
#authorize! ⇒ Object
102 103 104 105 |
# File 'lib/locman/manager.rb', line 102 def return true unless CLLocationManager. == KCLAuthorizationStatusNotDetermined manager.requestAlwaysAuthorization end |
#authorized?(status = nil) ⇒ Boolean
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/locman/manager.rb', line 107 def (status = nil) status ||= CLLocationManager. if AUTHORIZED_CONSTS.include? status return true elsif NOT_AUTHORIZED_CONSTS.include? status return false end nil end |
#locationManager(manager, didVisit: cl_visit) ⇒ Object
Delegates
149 150 151 |
# File 'lib/locman/manager.rb', line 149 def locationManager(manager, didChangeAuthorizationStatus: status) .call((status)) unless .nil? end |
#stop_update! ⇒ Object
127 128 129 |
# File 'lib/locman/manager.rb', line 127 def stop_update! manager.stopUpdatingLocation end |
#stop_update_significant! ⇒ Object
135 136 137 |
# File 'lib/locman/manager.rb', line 135 def stop_update_significant! manager.stopMonitoringSignificantLocationChanges end |
#stop_update_visits! ⇒ Object
143 144 145 |
# File 'lib/locman/manager.rb', line 143 def stop_update_visits! manager.stopMonitoringVisits end |
#update! ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/locman/manager.rb', line 119 def update! if CLLocationManager. != KCLAuthorizationStatusAuthorized fail(Exception, "Location permission is not authorized by user") end manager.startUpdatingLocation end |
#update_significant! ⇒ Object
131 132 133 |
# File 'lib/locman/manager.rb', line 131 def update_significant! manager.startMonitoringSignificantLocationChanges end |
#update_visits! ⇒ Object
139 140 141 |
# File 'lib/locman/manager.rb', line 139 def update_visits! manager.startMonitoringVisits end |