Class: ProximityTrigger

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

Overview

Category: Sensors

Instance Attribute Summary

Attributes inherited from Trigger

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ ProximityTrigger

Returns a new instance of ProximityTrigger.



1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/ruby-macrodroid/triggers.rb', line 1402

def initialize(obj=nil)

  h = if obj.is_a? Hash then
    obj
  elsif obj.is_a? Array
    e, macro = obj
    txt = e.text('item/description')
    {option: (txt || e.text), macro: macro}
  end 
  
  options = {
    near: true,
    selected_option: 0
  }
  
  if h[:distance] then
    
    case h[:distance].to_sym
    when :near
      options[:near] = true
    end
  end
  
  super(options.merge h)

end

Instance Method Details

#match?(detail = {}, model = nil) ⇒ Boolean

Returns:

  • (Boolean)


1429
1430
1431
# File 'lib/ruby-macrodroid/triggers.rb', line 1429

def match?(detail={}, model=nil)
  @h[:selected_option] == detail[:option].to_i
end

#to_s(colour: false) ⇒ Object Also known as: to_summary



1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File 'lib/ruby-macrodroid/triggers.rb', line 1433

def to_s(colour: false)
  
  distance = if @h[:near] then
    'Near'
  else
    'Far'
  end
  
  @s = "Proximity Sensor (%s)" % distance
  super()
end