Class: ConstraintsNlp
- Inherits:
-
Object
- Object
- ConstraintsNlp
- Includes:
- AppRoutes
- Defined in:
- lib/ruby-macrodroid/macro.rb
Instance Method Summary collapse
- #constraints(params) ⇒ Object
-
#initialize ⇒ ConstraintsNlp
constructor
A new instance of ConstraintsNlp.
Constructor Details
#initialize ⇒ ConstraintsNlp
Returns a new instance of ConstraintsNlp.
389 390 391 392 393 394 395 |
# File 'lib/ruby-macrodroid/macro.rb', line 389 def initialize() super() params = {} constraints(params) end |
Instance Method Details
#constraints(params) ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 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 |
# File 'lib/ruby-macrodroid/macro.rb', line 397 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+) (=) (\[?\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 |