Class: IStats::Fan

Inherits:
Object
  • Object
show all
Extended by:
FAN_STATS
Defined in:
lib/iStats/fan.rb

Class Method Summary collapse

Methods included from FAN_STATS

get_fan_number, get_fan_speed

Class Method Details

.allObject

Call all functions (stats)



26
27
28
29
# File 'lib/iStats/fan.rb', line 26

def all
  print_fan_number
  fans_speed
end

.delegate(stat) ⇒ Object

Delegate CLI command to function



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/iStats/fan.rb', line 11

def delegate(stat)
  case stat
  when 'all'
    all
  when 'number', 'num'
    print_fan_number
  when 'speed'
    fans_speed
  else
    Command.help "Unknown stat for Fan: #{stat}"
  end
end

.fan_numberObject

Get the number of fans on system Calls a C method from FAN_STATS module



34
35
36
# File 'lib/iStats/fan.rb', line 34

def fan_number
  get_fan_number
end

.fans_speedObject

Get and print the speed of each fan



46
47
48
49
50
51
52
53
# File 'lib/iStats/fan.rb', line 46

def fans_speed
  fanNum = fan_number
  (0..(fanNum-1)).each do |n|
    s = get_fan_speed(n)
    s = s.round unless s.nil?
    print_fan_speed(n, s)
  end
end

Print number of fan(s)



40
41
42
# File 'lib/iStats/fan.rb', line 40

def print_fan_number
  Printer.print_item_line("Total fans in system", fan_number)
end

Actually print fan speed with Sparkline

fanNum - The fan number speed - Fan speed in RPM



60
61
62
63
# File 'lib/iStats/fan.rb', line 60

def print_fan_speed(fanNum, speed)
  thresholds = [2500, 3500, 4500, 5500]
  Printer.print_item_line("Fan #{fanNum} speed", speed, " RPM", thresholds)
end