Class: TaskLoop::AfterScopeRule

Inherits:
ScopeRule show all
Defined in:
lib/taskloop/rules/after_scope_rule.rb

Constant Summary

Constants inherited from ScopeRule

ScopeRule::SCOPE

Constants inherited from Rule

Rule::UNIT

Instance Attribute Summary collapse

Attributes inherited from ScopeRule

#scope

Attributes inherited from Rule

#unit

Instance Method Summary collapse

Constructor Details

#initialize(unit, left) ⇒ AfterScopeRule

Returns a new instance of AfterScopeRule.



6
7
8
9
# File 'lib/taskloop/rules/after_scope_rule.rb', line 6

def initialize(unit, left)
  super unit, :after
  @left = left
end

Instance Attribute Details

#leftObject

Returns the value of attribute left.



4
5
6
# File 'lib/taskloop/rules/after_scope_rule.rb', line 4

def left
  @left
end

Instance Method Details

#descObject



80
81
82
# File 'lib/taskloop/rules/after_scope_rule.rb', line 80

def desc
  super + " #{left}"
end

#is_conform_rule?(last_exec_time) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/taskloop/rules/after_scope_rule.rb', line 59

def is_conform_rule?(last_exec_time)
  current = Time.now
  value = left_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

#left_valueObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/taskloop/rules/after_scope_rule.rb', line 41

def left_value
  if (Task::DAY.has_key?(@left))
    return Task::DAY[@left]
  end
  if (Task::WEEK.has_key?(@left))
    return Task::WEEK[@left]
  end
  if (Task::MONTH.has_key?(@left))
    return Task::MONTH[@left]
  end

  unless @left != nil && @left.is_a?(Integer)
    return -1
  end

  return @left
end