Class: Stf::Device

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/stf/model/device.rb

Instance Method Summary collapse

Instance Method Details

#checkFilter?(filter) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/stf/model/device.rb', line 37

def checkFilter?(filter)
  return true if filter.nil?
  key, value = filter.split(':', 2)
  getValue(key) == value
end

#getKeysObject



7
8
9
# File 'lib/stf/model/device.rb', line 7

def getKeys
  getKeysNextLevel('', self)
end

#getValue(key) ⇒ Object



3
4
5
# File 'lib/stf/model/device.rb', line 3

def getValue(key)
  getValueFromObject(self, key)
end

#healthy?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stf/model/device.rb', line 23

def healthy?(pattern)
  return true if pattern.nil?
  ppp = pattern.split(',')
  health = true
  ppp.each do |p|
    health &&= getValue('battery.temp').to_i < 32 if ['t', 'temp', 'temperature'].include? p
    health &&= getValue('battery.level').to_f > 20.0 if ['b', 'batt', 'battery'].include? p
    health &&= getValue('network.connected') if ['n', 'net', 'network'].include? p
    health &&= getValue('network.type') == 'VPN' if ['vpn'].include? p
    health &&= getValue('network.type') == 'WIFI' if ['wifi'].include? p
  end
  health
end

#healthy_for_connect?(pattern) ⇒ Boolean

more pessimistic decision

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/stf/model/device.rb', line 12

def healthy_for_connect?(pattern)
  return true if pattern.nil?
  health = healthy?(pattern)
  ppp = pattern.split(',')
  ppp.each do |p|
    health &&= getValue('battery.temp').to_i < 30 if ['t', 'temp', 'temperature'].include? p
    health &&= getValue('battery.level').to_f > 30.0 if ['b', 'batt', 'battery'].include? p
  end
  health
end