Class: TaskLoop::BeforeScopeRule
- Defined in:
- lib/taskloop/rules/before_scope_rule.rb
Constant Summary
Constants inherited from ScopeRule
Constants inherited from Rule
Instance Attribute Summary collapse
-
#right ⇒ Object
Returns the value of attribute right.
Attributes inherited from ScopeRule
Attributes inherited from Rule
Instance Method Summary collapse
- #desc ⇒ Object
-
#initialize(unit, right) ⇒ BeforeScopeRule
constructor
A new instance of BeforeScopeRule.
- #is_conform_rule?(last_exec_time) ⇒ Boolean
-
#right_value ⇒ Object
def invalidate! super if @unit == :day unless Task::WEEK.has_key?(@right) || Task::DAY.has_key?(@right) raise ArgumentError, “#@right must be a Symbol defined in Task::WEEK or Task::DAY” end return end.
Constructor Details
#initialize(unit, right) ⇒ BeforeScopeRule
Returns a new instance of BeforeScopeRule.
6 7 8 9 |
# File 'lib/taskloop/rules/before_scope_rule.rb', line 6 def initialize(unit, right) super unit, :before @right = right end |
Instance Attribute Details
#right ⇒ Object
Returns the value of attribute right.
4 5 6 |
# File 'lib/taskloop/rules/before_scope_rule.rb', line 4 def right @right end |
Instance Method Details
#desc ⇒ Object
79 80 81 |
# File 'lib/taskloop/rules/before_scope_rule.rb', line 79 def desc super + " #{right}" end |
#is_conform_rule?(last_exec_time) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/taskloop/rules/before_scope_rule.rb', line 58 def is_conform_rule?(last_exec_time) current = Time.now value = right_value result = false case @unit when :year then result = current.year <= value when :month then result = current.month <= value when :week then result = current.wday <= value when :day then result = current.day <= value when :hour then result = current.hour <= value when :minute then result = current.min <= value end return result end |
#right_value ⇒ Object
def invalidate!
super
if @unit == :day
unless Task::WEEK.has_key?(@right) || Task::DAY.has_key?(@right)
raise ArgumentError, "#{@right} must be a Symbol defined in Task::WEEK or Task::DAY"
end
return
end
if @unit == :month
unless Task::MONTH.has_key?(@right)
raise ArgumentError, "#{@right} must be a Symbol defined in Task::MONTH"
end
return
end
unless @right.is_a?(Integer)
raise TypeError, "'right' need to be Symbol or Integer"
end
if @unit == :minute && (@right < 0 || @right > 59)
raise ArgumentError, "'right' for 'minute' must >= 0 and <= 59"
end
if @unit == :hour && (@right < 0 || @right > 23)
raise ArgumentError, "'right' for 'hour' must >= 0 and <= 23"
end
end
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/taskloop/rules/before_scope_rule.rb', line 40 def right_value if (Task::DAY.has_key?(@right)) return Task::DAY[@right] end if (Task::WEEK.has_key?(@right)) return Task::WEEK[@right] end if (Task::MONTH.has_key?(@right)) return Task::MONTH[@right] end unless @right != nil && @right.is_a?(Integer) return -1 end return @right end |