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



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

def disable_graphs
  @display_graphs = false
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


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/iStats/printer.rb', line 17

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