Class: Ayadn::Validators
Class Method Summary collapse
- .boolean(value) ⇒ Object
- .color(color) ⇒ Object
- .index_range(min, max, value) ⇒ Object
- .threshold(value) ⇒ Object
- .timer(t) ⇒ Object
- .URL(str) ⇒ Object
- .width_range(value) ⇒ Object
Class Method Details
.boolean(value) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/ayadn/set.rb', line 260 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
303 304 305 306 307 308 309 310 311 312 |
# File 'lib/ayadn/set.rb', line 303 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
272 273 274 275 276 277 278 279 |
# File 'lib/ayadn/set.rb', line 272 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
289 290 291 292 293 294 295 296 |
# File 'lib/ayadn/set.rb', line 289 def self.threshold value value = value.to_f if value > 0 and value < 5 value else Status.new.threshold end end |
.timer(t) ⇒ Object
298 299 300 301 |
# File 'lib/ayadn/set.rb', line 298 def self.timer(t) t = t.to_f.round t >= 1 ? t : 3 end |
.URL(str) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/ayadn/set.rb', line 243 def self.URL(str) require 'net/http' if(str.to_s.empty?) Status.new.error_missing_parameters exit end begin URI.parse(str) # if url.host.nil? || (url.scheme != 'http' && url.scheme != 'https') # ask: are you sure about this url? # end # url rescue URI::Error => e return nil end end |
.width_range(value) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/ayadn/set.rb', line 281 def self.width_range value if value >= 60 && value <= 90 value.round else 75 end end |