Class: GeofenceTrigger

Inherits:
Trigger show all
Defined in:
lib/ruby-macrodroid/triggers.rb

Overview

Category: Location

Instance Attribute Summary

Attributes inherited from Trigger

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Trigger

#match?

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}, geofences: {}) ⇒ GeofenceTrigger

Returns a new instance of GeofenceTrigger.



1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
# File 'lib/ruby-macrodroid/triggers.rb', line 1265

def initialize( h={}, geofences: {})

  if h[:name] then
    puts ('geofences2: ' + geofences.inspect) if $debug
    found = geofences.find {|x| x.name.downcase == h[:name].downcase}
    h[:geofence_id] = found.id if found
    
  end
  
  options = {
    update_rate_text: '5 Minutes',
    geofence_id: '',
    geofence_update_rate_minutes: 5,
    trigger_from_unknown: false,
    enter_area: true
  }

  super(options.merge filter(options, h))
  @geofences = geofences

end

Instance Method Details

#to_s(colour: false) ⇒ Object



1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
# File 'lib/ruby-macrodroid/triggers.rb', line 1287

def to_s(colour: false)
  
  if $debug then
    puts ' @geofences: ' + @geofences.inspect
    puts '@h: ' + @h.inspect
    puts '@h[:geofence_id]: ' + @h[:geofence_id].inspect
  end
  
  direction = @h[:enter_area] ? 'Entry' : 'Exit'
  
  found = @geofences.find {|x| x.id == @h[:geofence_id]}
  puts 'found: ' + found.inspect    if @debug 
  label = found ? found.name : 'error: name not found'

  "Geofence %s (%s)" % [direction, label]
  
end