Class: Ayadn::Validators

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

Class Method Summary collapse

Class Method Details

.boolean(value) ⇒ Object



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

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

.color(color) ⇒ Object



252
253
254
255
256
257
258
259
260
261
# File 'lib/ayadn/set.rb', line 252

def self.color(color)
  colors_list = %w{red green magenta cyan yellow blue white black}
  unless colors_list.include?(color.to_s)
    Status.new.error_missing_parameters
    Status.new.valid_colors(colors_list)
    exit
  else
    return color.to_sym
  end
end

.index_range(min, max, value) ⇒ Object



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

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

.threshold(value) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/ayadn/set.rb', line 238

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

.timer(t) ⇒ Object



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

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

.width_range(value) ⇒ Object



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

def self.width_range value
  if value >= 60 && value <= 90
    value.round
  else
    75
  end
end