Class: OpenWFE::CronLine

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/util/scheduler.rb

Overview

A ‘cron line’ is a line in the sense of a crontab (man 5 crontab) file line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ CronLine

Returns a new instance of CronLine.



1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
# File 'lib/openwfe/util/scheduler.rb', line 1091

def initialize (line)

    super()

    @original = line

    items = line.split

    unless [ 5, 6 ].include?(items.length)
        raise \
            "cron '#{line}' string should hold 5 or 6 items, " +
            "not #{items.length}" \
    end

    offset = items.length - 5

    @seconds = if offset == 1
        parse_item(items[0], 0, 59)
    else
        [ 0 ]
    end
    @minutes = parse_item(items[0+offset], 0, 59)
    @hours = parse_item(items[1+offset], 0, 24)
    @days = parse_item(items[2+offset], 1, 31)
    @months = parse_item(items[3+offset], 1, 12)
    @weekdays = parse_weekdays(items[4+offset])

    #adjust_arrays()
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



1083
1084
1085
# File 'lib/openwfe/util/scheduler.rb', line 1083

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



1083
1084
1085
# File 'lib/openwfe/util/scheduler.rb', line 1083

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



1083
1084
1085
# File 'lib/openwfe/util/scheduler.rb', line 1083

def minutes
  @minutes
end

#monthsObject (readonly)

Returns the value of attribute months.



1083
1084
1085
# File 'lib/openwfe/util/scheduler.rb', line 1083

def months
  @months
end

#originalObject (readonly)

The string used for creating this cronline instance.



1081
1082
1083
# File 'lib/openwfe/util/scheduler.rb', line 1081

def original
  @original
end

#secondsObject (readonly)

Returns the value of attribute seconds.



1083
1084
1085
# File 'lib/openwfe/util/scheduler.rb', line 1083

def seconds
  @seconds
end

#weekdaysObject (readonly)

Returns the value of attribute weekdays.



1083
1084
1085
# File 'lib/openwfe/util/scheduler.rb', line 1083

def weekdays
  @weekdays
end

Instance Method Details

#matches?(time) ⇒ Boolean

Returns true if the given time matches this cron line.

Returns:

  • (Boolean)


1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/openwfe/util/scheduler.rb', line 1124

def matches? (time)

    time = Time.at(time) \
        if time.kind_of?(Float) or time.kind_of?(Integer)

    return false if no_match?(time.sec, @seconds)
    return false if no_match?(time.min, @minutes)
    return false if no_match?(time.hour, @hours)
    return false if no_match?(time.day, @days)
    return false if no_match?(time.month, @months)
    return false if no_match?(time.wday, @weekdays)

    true
end

#to_arrayObject

Returns an array of 6 arrays (seconds, minutes, hours, days, months, weekdays). This method is used by the cronline unit tests.



1144
1145
1146
# File 'lib/openwfe/util/scheduler.rb', line 1144

def to_array
    [ @seconds, @minutes, @hours, @days, @months, @weekdays ]
end