Class: IStats::Printer

Inherits:
Object
  • Object
show all
Extended by:
Color
Defined in:
lib/iStats/printer.rb

Constant Summary

Constants included from Color

Color::CODES

Class Method Summary collapse

Methods included from Color

colorize, included

Class Method Details

.disable_graphsObject



9
10
11
# File 'lib/iStats/printer.rb', line 9

def disable_graphs
  @display_graphs = false
end

.format_temperature(temperature) ⇒ Object

Pretty print temperature values. Also converts the value to the class temperature_scale.

Returns the temperature string.



50
51
52
53
54
55
56
# File 'lib/iStats/printer.rb', line 50

def format_temperature(temperature)
  if @temperature_scale == 'celcius'
    "#{temperature.round(2)}#{Symbols.degree}C"
  else
    "#{Utils.to_fahrenheit(temperature).round(2)}#{Symbols.degree}F"
  end
end

.gen_sparkline(value, thresholds) ⇒ Object

Create colored sparkline value - The stat value thresholds - must be an array of size 4 containing the threshold values

for the sparkline colors


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/iStats/printer.rb', line 22

def gen_sparkline(value, thresholds)
  # Graphs can be disabled globally
  return '' unless @display_graphs

  return if thresholds.count < 4

  list = [0, 30, 55, 80, 100, 130]
  sparkline = Sparkr.sparkline(list) do |tick, count, index|
    if index.between?(0, 5) and value > thresholds[3]
      flash_red(tick)
    elsif index.between?(0, 1)
      green(tick)
    elsif index.between?(2, 3) and value > thresholds[0]
      light_yellow(tick)
    elsif index == 4 and value > thresholds[1]
      yellow(tick)
    elsif index == 5 and value > thresholds[2]
      red(tick)
    else
      tick
    end
  end
end

.set_temperature_scale(scale) ⇒ Object



13
14
15
# File 'lib/iStats/printer.rb', line 13

def set_temperature_scale(scale)
  @temperature_scale = scale
end