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
- .width_range(value) ⇒ Object
Class Method Details
.boolean(value) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ayadn/set.rb', line 162 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
182 183 184 185 186 187 188 |
# File 'lib/ayadn/set.rb', line 182 def self.cache_range value if value >= 1 && value <= 168 value.round else abort(Status.cache_range) end end |
.color(color) ⇒ Object
212 213 214 215 216 217 218 219 220 |
# File 'lib/ayadn/set.rb', line 212 def self.color(color) colors_list = %w{red green magenta cyan yellow blue white black} unless colors_list.include?(color.to_s) puts Status.error_missing_parameters abort(Status.valid_colors(colors_list)) else return color.to_sym end end |
.index_range(min, max, value) ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/ayadn/set.rb', line 173 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
198 199 200 201 202 203 204 205 |
# File 'lib/ayadn/set.rb', line 198 def self.threshold value value = value.to_f if value > 0 and value < 5 value else abort(Status.threshold) end end |
.timer(t) ⇒ Object
207 208 209 210 |
# File 'lib/ayadn/set.rb', line 207 def self.timer(t) t = t.to_f.round t >= 1 ? t : 3 end |
.width_range(value) ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/ayadn/set.rb', line 190 def self.width_range value if value >= 60 && value <= 90 value.round else 75 end end |