Last active
August 29, 2015 14:02
-
-
Save mattjbarlow/5dd213adc0265a7ca7a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.validate_numeric(spec, min, max) | |
# binding.pry | |
if spec.is_a? Fixnum | |
return false unless spec >= min && spec <= max | |
return true | |
end | |
# Lists of invidual values, ranges, and step values all share the validity range for type | |
spec.split(/\/|-|,/).each do |x| | |
next if x == '*' | |
if x =~ /^\d+$/ | |
x = x.to_i | |
return false unless x >= min && x <= max | |
else | |
return false | |
end | |
end | |
true | |
end | |
def self.validate_dow(spec) | |
# 0-7 are legal for days of week | |
validate_numeric(spec, 0, 7) | |
return true if spec == '*' | |
# Named abbreviations are permitted but not as part of a range or with stepping | |
return true if %w(sun mon tue wed thu fri sat).include? spec.downcase | |
end | |
undefined method `downcase' for 6:Fixnum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment