Class: AirplaneModeConstraint

Inherits:
Constraint show all
Defined in:
lib/ruby-macrodroid/constraints.rb

Overview

Category: Device State

Instance Attribute Summary

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}) ⇒ AirplaneModeConstraint

Returns a new instance of AirplaneModeConstraint.



571
572
573
574
575
576
577
578
579
# File 'lib/ruby-macrodroid/constraints.rb', line 571

def initialize(h={})

  options = {
    enabled: true
  }

  super(options.merge h)

end

Instance Method Details

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

Returns:

  • (Boolean)


581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/ruby-macrodroid/constraints.rb', line 581

def match?(detail={}, model=nil)
  
  puts 'inside airplaneModeConstraint#match?' if $debug
  
  if detail.has_key? :enabled then
    
    puts 'detail has the key' if $debug
    super(detail)
    
  elsif model
    
    if $debug then
      puts 'checking the model'
      switch = model.connectivity.airplane_mode.switch
      puts 'switch: ' + switch.inspect
    end
    
    toggle_match?(:enabled, switch)
    
  end
  
end

#to_pcObject



604
605
606
607
# File 'lib/ruby-macrodroid/constraints.rb', line 604

def to_pc()
  status = @h[:enabled] ? 'enabled?' : 'disabled?'
  'airplane_mode.' + status
end

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



609
610
611
612
613
614
# File 'lib/ruby-macrodroid/constraints.rb', line 609

def to_s(colour: false, indent: 0)
  
  status = @h[:enabled] ? 'Enabled' : 'Disabled'
  'Airplane Mode ' + status
  
end