Class: Yummi::Colorizers::PercentageColorizer

Inherits:
Object
  • Object
show all
Includes:
Yummi::Colorizer
Defined in:
lib/yummi/colorizers.rb

Instance Method Summary collapse

Methods included from Yummi::Colorizer

#color_for, #colorize

Constructor Details

#initialize(params) ⇒ PercentageColorizer

Returns a new instance of PercentageColorizer.



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/yummi/colorizers.rb', line 195

def initialize(params)
  @max = params[:max].to_sym
  @free = params[:free]
  @using = params[:using]
  color = {
    :bad => :red,
    :warn => :yellow,
    :good => :green
  }.merge!(params[:colors] || {})
  threshold = {
    :warn => 0.30,
    :bad => 0.15,
    :good => 1
  }.merge!(params[:threshold] || {})

  threshold_params = { :mode => :max }
  color.each do |type, name|
    threshold_params[threshold[type]] = name
  end
  @threshold = Yummi::Colorizers.threshold threshold_params
end

Instance Method Details

#call(data) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/yummi/colorizers.rb', line 217

def call(data)
  max = data[@max].to_f
  free = @using ? max - data[@using.to_sym].to_f : data[@free.to_sym].to_f

  percentage = free / max

  @threshold.color_for(percentage)
end