Class: BatteryLevelConstraint

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

Overview

Category: Battery/Power

Instance Attribute Summary

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Constraint

#match?

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}) ⇒ BatteryLevelConstraint

Returns a new instance of BatteryLevelConstraint.



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ruby-macrodroid/constraints.rb', line 97

def initialize(h={})

  options = {
    battery_level: 23,
    equals: false,
    greater_than: false
  }

  super(options.merge h)

end

Instance Method Details

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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ruby-macrodroid/constraints.rb', line 109

def to_s(colour: false, indent: 0)
  
  operator = if @h[:greater_than] then
    '>'
  elsif @h[:equals]
    '='
  else
    '<'
  end
  
  level = @h[:battery_level]
  
  "Battery %s %s%%" % [operator, level]
end