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.



1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File 'lib/ruby-macrodroid/triggers.rb', line 1218

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



1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'lib/ruby-macrodroid/triggers.rb', line 1240

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