Class: Locman::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/locman/manager.rb

Overview

This wraps CLLocationManager in more Ruby way.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Locman::Manager

Creates a new Locman::Location instance.

Parameters:

  • options (Hash)

    Attributes that will be assigned on instance creation



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

#accuracySymbol

Returns Desired accuracy of the location data.

Returns:

  • (Symbol)

    Desired accuracy of the location data.



5
6
7
# File 'lib/locman/manager.rb', line 5

def accuracy
  @accuracy
end

#backgroundBoolean

Returns Set whether location should be updated in the background or not.

Returns:

  • (Boolean)

    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_filterInteger

Returns The minimum horizontal distance threshold for on_update event.

Returns:

  • (Integer)

    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_errorProc

Returns Proc function that will be called when there is an error while retrieving the location.

Returns:

  • (Proc)

    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_updateProc

Returns Proc function that will be called when there is a new location retrieval.

Returns:

  • (Proc)

    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_visitProc

Returns Proc function that will be called when there is a new visit event.

Returns:

  • (Proc)

    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 after_authorize=(after_authorize)
  fail(ArgumentError, "Must provide proc") unless after_authorize.is_a?(Proc)
  @after_authorize = after_authorize
end

#authorize!Object



102
103
104
105
# File 'lib/locman/manager.rb', line 102

def authorize!
  return true unless CLLocationManager.authorizationStatus == KCLAuthorizationStatusNotDetermined
  manager.requestAlwaysAuthorization
end

#authorized?(status = nil) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
110
111
112
113
114
115
116
117
# File 'lib/locman/manager.rb', line 107

def authorized?(status = nil)
  status ||= CLLocationManager.authorizationStatus

  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)
  @after_authorize.call(authorized?(status)) unless @after_authorize.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.authorizationStatus != 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