Skip to content

Instantly share code, notes, and snippets.

@mattjbarlow
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattjbarlow/5dd213adc0265a7ca7a7 to your computer and use it in GitHub Desktop.
Save mattjbarlow/5dd213adc0265a7ca7a7 to your computer and use it in GitHub Desktop.
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