Class: CLBeaconRegion

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-beacon/clbeaconregion.rb

Overview

extended BeaconRegion class with list of beacons and helper methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#beaconsObject

Returns the value of attribute beacons.



4
5
6
# File 'lib/motion-beacon/clbeaconregion.rb', line 4

def beacons
  @beacons
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/motion-beacon/clbeaconregion.rb', line 5

def timeout
  @timeout
end

Instance Method Details

#distanceObject



7
8
9
10
11
12
13
14
# File 'lib/motion-beacon/clbeaconregion.rb', line 7

def distance
  if @beacons.empty? then
    return 99999
  else
    beaconMin = @beacons.min { |a, b| a.accuracy <=> b.accuracy }
    beaconMin.accuracy
  end
end

#hasBeacon?(major, minor) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/motion-beacon/clbeaconregion.rb', line 16

def hasBeacon?(major, minor)
  @beacons.each { |beacon|
    if not major.nil? then
      if minor.nil? then
        if beacon.major == major then
          return true
        end
      else
        if beacon.major == major and beacon.minor == minor then
          return true
        end
      end
    end
  }
  false
end

#printBeaconsObject



38
39
40
41
42
43
44
45
46
# File 'lib/motion-beacon/clbeaconregion.rb', line 38

def printBeacons
  @beacons.each { |beacon|
    NSLog("beacon: [major]: " + beacon.major.to_s +
    " [minor]: " + beacon.minor.to_s +
    " [proximity]: " + beacon.proximity.to_s +
    " [accuracy]: " + beacon.accuracy.to_s +
    " [rssi]: " + beacon.rssi.to_s)
  }
end

#to_sObject



33
34
35
36
# File 'lib/motion-beacon/clbeaconregion.rb', line 33

def to_s
    "region: [major]: " + major.to_s +
    " [minor]: " + minor.to_s
end