Class: IStats::Extra

Inherits:
Object
  • Object
show all
Extended by:
SMC_INFO
Defined in:
lib/iStats/extra.rb

Class Method Summary collapse

Methods included from SMC_INFO

is_key_supported

Class Method Details

.allObject

Prints temperature for all enabled keys



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/iStats/extra.rb', line 21

def all
  sensors = $config.params
  display = sensors['AltDisplay']
  if sensors.keys.any? {|key| sensors[key]['enabled'] == "1"}
    sensors.keys.each{ |key|
      if (sensors[key]['enabled'] == "1")
        extra_enabled = true
        display_temp(key, sensors[key], display)
      end
    }
  else
    puts "Looks like you don't have any extra keys enabled. \nRun `istats scan` for the initial scan or `istats --help` for more info."
  end
end

.delegate(stat) ⇒ Object

Delegate CLI command to function



11
12
13
14
15
16
17
# File 'lib/iStats/extra.rb', line 11

def delegate(stat)
  if stat == 'all'
    all
  else
    sensor_temperature stat
  end
end

.display_temp(key, sensor, display) ⇒ Object

Pretty print sensor temperature



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/iStats/extra.rb', line 50

def display_temp(key, sensor, display)
  t = SMC.is_key_supported(key).round(2);
  value, scale = Printer.parse_temperature(t)

  thresholds = sensor['thresholds'][1..-2].split(/, /).map { |s| s.to_i }

  if Printer.get_temperature_scale == 'fahrenheit'
    thresholds.map! { |t| Utils.to_fahrenheit(t) }
  end

  if (display)
    # Invoked if settings has an AltDisplay?
    puts "#{Printer.format_label("#{key}")}" +
         "#{Printer.format_temperature(t)}#{Printer.gen_sparkline(t, thresholds)}" +
         "#{Printer.format_label(" #{sensor['name']}")}"
  else
    Printer.print_item_line("#{key} #{sensor['name']} temp", value, scale, thresholds)
  end
end

.sensor_temperature(key) ⇒ Object

Prints temperature for specific key



38
39
40
41
42
43
44
45
46
47
# File 'lib/iStats/extra.rb', line 38

def sensor_temperature(key)
  sensors = $config.params
  display = sensors['AltDisplay']
  sensor = sensors[key]
  if sensor.nil?
    Command.help "Unknown sensor: #{stat}"
  else
    display_temp(key, sensor, display)
  end
end