Class: ConstraintsNlp

Inherits:
Object
  • Object
show all
Includes:
AppRoutes
Defined in:
lib/ruby-macrodroid/macro.rb

Instance Method Summary collapse

Constructor Details

#initializeConstraintsNlp

Returns a new instance of ConstraintsNlp.



415
416
417
418
419
420
421
# File 'lib/ruby-macrodroid/macro.rb', line 415

def initialize()

  super()
  params = {}
  constraints(params)

end

Instance Method Details

#constraints(params) ⇒ Object



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/ruby-macrodroid/macro.rb', line 423

def constraints(params) 
  
  # Device State        
  
  get /^Device (locked|unlocked)/i do |state|
    [DeviceLockedConstraint, {locked: state.downcase == 'locked'}]
  end

  get /^airplane mode (.*)/i do |state|
    [AirplaneModeConstraint, {enabled: (state =~ /^enabled|on$/i) == 0}]
  end
  
  # 
  
  # -- MacroDroid specific -----------------------------------------------------------------------
  
  get /^(\w+) (=) (.*)/i do |loperand, operator, roperand|
    
    h = {
      loperand: loperand, 
      operator: operator, 
      roperand: roperand
    }
    
    [MacroDroidVariableConstraint, h]
    
  end
  
  # -- Sensors -----------------------------------
  #
  get /^Light Sensor (Less|Greater) than (50.0)lx/i do |operator, val|

    level, option = operator.downcase == 'less' ? [-1,0] : [1,1]
    
    h = {
      light_level: level,
      light_level_float: val,
      option: option
    }
    
    [LightLevelConstraint, h]
  end
  
  get /^Proximity Sensor: (Near|Far)/i do |distance|      
    [ProximitySensorConstraint, {near: distance.downcase == 'near'}]
  end
  
  
  # -- Screen and Speaker ---------------------------
  #
  get /^Screen (On|Off)/i do |state|      
    [ScreenOnOffConstraint, {screen_on: state.downcase == 'on'}]
  end    

end