Class: ConstraintsNlp
- Inherits:
-
Object
- Object
- ConstraintsNlp
- Includes:
- AppRoutes
- Defined in:
- lib/ruby-macrodroid/constraintsnlp.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.
9 10 11 12 13 14 15 |
# File 'lib/ruby-macrodroid/constraintsnlp.rb', line 9 def initialize() super() params = {} constraints(params) end |
Instance Method Details
#constraints(params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby-macrodroid/constraintsnlp.rb', line 17 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 |