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

.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


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/iStats/printer.rb', line 11

def gen_sparkline(value, thresholds)
  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