Class: Ayadn::Validators

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/set.rb

Class Method Summary collapse

Class Method Details

.boolean(value) ⇒ Object



210
211
212
213
214
215
216
217
218
219
# File 'lib/ayadn/set.rb', line 210

def self.boolean(value)
  case value.downcase
  when "true", "1", "yes"
    true
  when "false", "0", "no"
    false
  else
    abort(Status.error_missing_parameters)
  end
end

.cache_range(value) ⇒ Object



228
229
230
231
232
233
234
# File 'lib/ayadn/set.rb', line 228

def self.cache_range value
  if value >= 1 && value <= 168
    value.round
  else
    abort(Status.cache_range)
  end
end

.color(color) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/ayadn/set.rb', line 247

def self.color(color)
  colors_list = %w{red green magenta cyan yellow blue white black}
  unless colors_list.include?(color)
    puts Status.error_missing_parameters
    abort(Status.valid_colors(colors_list))
  end
end

.index_range(min, max, value) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/ayadn/set.rb', line 220

def self.index_range(min, max, value)
  x = value.to_i
  if x >= min && x <= max
    x
  else
    abort(Status.must_be_integer)
  end
end

.threshold(value) ⇒ Object



235
236
237
238
239
240
241
242
# File 'lib/ayadn/set.rb', line 235

def self.threshold value
  value = value.to_f
  if value > 0 and value < 5
    value
  else
    abort(Status.threshold)
  end
end

.timer(t) ⇒ Object



243
244
245
246
# File 'lib/ayadn/set.rb', line 243

def self.timer(t)
  t = t.to_i
  t >= 1 ? t : 3
end