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
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/ayadn/set.rb', line 234 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
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/ayadn/set.rb', line 277 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
246 247 248 249 250 251 252 253 |
# File 'lib/ayadn/set.rb', line 246 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
263 264 265 266 267 268 269 270 |
# File 'lib/ayadn/set.rb', line 263 def self.threshold value value = value.to_f if value > 0 and value < 5 value else Status.new.threshold end end |
.timer(t) ⇒ Object
272 273 274 275 |
# File 'lib/ayadn/set.rb', line 272 def self.timer(t) t = t.to_f.round t >= 1 ? t : 3 end |
.URL(str) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/ayadn/set.rb', line 217 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
255 256 257 258 259 260 261 |
# File 'lib/ayadn/set.rb', line 255 def self.width_range value if value >= 60 && value <= 90 value.round else 75 end end |