Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/cerberus/utils.rb

Instance Method Summary collapse

Instance Method Details

#cron_match?(number) ⇒ Boolean

Returns:

  • (Boolean)


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cerberus/utils.rb', line 165

def cron_match?(number)
  return false if not number.is_a?(Integer)
  return true if self == "*"
  parts = self.split(",")
  parts.each do |p|
    match = p.match(/(\d+|\*)-?(\d+)?(\/(\d+))?$/)
    return false if not match
    if not match[2]
      if match[1] == "*" and match[4]
        return true if number % match[4].to_i == 0
      end
      return true if match[1].to_i == number
    else
      range = (match[1].to_i)..(match[2].to_i)
      if not match[3]
        return true if range.include?(number)
      else
        range.each do |r|
          if (r - range.first) % match[4].to_i == 0
            return true if r == number
          end
        end
      end
    end
  end
  return false
end