Class: Ayadn::Validators
- Inherits:
-
Object
- Object
- Ayadn::Validators
- Defined in:
- lib/ayadn/set.rb
Class Method Summary collapse
- .boolean(value) ⇒ Object
- .cache_range(value) ⇒ Object
- .color(color) ⇒ Object
- .index_range(min, max, value) ⇒ Object
- .threshold(value) ⇒ Object
- .timer(t) ⇒ Object
Class Method Details
.boolean(value) ⇒ Object
276 277 278 279 280 281 282 283 284 285 |
# File 'lib/ayadn/set.rb', line 276 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
294 295 296 297 298 299 300 |
# File 'lib/ayadn/set.rb', line 294 def self.cache_range value if value >= 1 && value <= 168 value.round else abort(Status.cache_range) end end |
.color(color) ⇒ Object
313 314 315 316 317 318 319 |
# File 'lib/ayadn/set.rb', line 313 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
286 287 288 289 290 291 292 293 |
# File 'lib/ayadn/set.rb', line 286 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
301 302 303 304 305 306 307 308 |
# File 'lib/ayadn/set.rb', line 301 def self.threshold value value = value.to_f if value > 0 and value < 5 value else abort(Status.threshold) end end |
.timer(t) ⇒ Object
309 310 311 312 |
# File 'lib/ayadn/set.rb', line 309 def self.timer(t) t = t.to_i t >= 1 ? t : 3 end |