«
Rule languages supports Switches
| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | <initial_state> | 
# Invert all switches
items.select { |item| item.is_a? Switch }
     .each   { |switch| if switch.off? then switch.on else switch.off end}| initial_state | final_state | |
|---|---|---|
| ON | OFF | |
| OFF | ON | 
| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | <initial_state> | 
TestSwitch << <bool>| initial_state | bool | final_state | |
|---|---|---|---|
| OFF | true | ON | |
| ON | false | OFF | 
| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | <initial_state> | 
# Invert all switches
items.select { |item| item.is_a? Switch }
     .each   { |switch| switch.toggle }| initial_state | final_state | |
|---|---|---|
| ON | OFF | |
| OFF | ON | |
| UNDEF | ON | |
| NULL | ON | 
| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | <initial_state> | 
# Invert all switches
items.select { |item| item.is_a? Switch }
     .each   { |switch| switch << !switch }| initial_state | final_state | |
|---|---|---|
| ON | OFF | |
| OFF | ON | |
| NULL | ON | |
| UNDEF | ON | 
| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | ON | 
items.grep(Switch)
     .each { |switch| logger.info("Switch #{switch.id} found") }| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | ON | 
| Switch | TestSwitchTwo | Test Switch Two | OFF | 
items.grep(Switch)
     .grep(ON)
     .each { |switch| logger.info("#{switch.id} ON") }
items.grep(Switch)
     .grep(OFF)
     .each { |switch| logger.info("#{switch.id} OFF") }| type | name | label | state | 
|---|---|---|---|
| Switch | TestSwitch | Test Switch | ON | 
| Switch | TestSwitchTwo | Test Switch Two | OFF | 
items.grep(Switch)
     .each do |switch|
        case switch
        when ON
          logger.info("#{switch.id} ON")
        when OFF
          logger.info("#{switch.id} OFF")
        end
     end| type | name | label | state | group | 
|---|---|---|---|---|
| Switch | TestSwitch | Test Switch | <initial_state> | Switches | 
| Switch | TestSwitchTwo | Test Switch Two | <initial_state> | Switches | 
  Switches.each(&:<command>)| initial_state | command | final_state | |
|---|---|---|---|
| OFF | on | ON | |
| ON | off | OFF | 
| type | name | label | state | group | 
|---|---|---|---|---|
| Switch | TestSwitch | Test Switch | <initial_state> | Switches | 
| Switch | TestSwitchTwo | Test Switch Two | <initial_state> | Switches | 
  Switches.select(&:<check>).each(&:<command>)| initial_state | check | command | final_state | |
|---|---|---|---|---|
| OFF | off? | on | ON | |
| ON | on? | off | OFF |