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)


38
39
40
41
42
43
44
45
# File 'lib/stf/model/device.rb', line 38

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

#getKeysObject



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

def getKeys
  getKeysNextLevel('', self)
end

#getValue(key) ⇒ Object



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

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

#healthy?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

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