Class: TaskLoop::TimeListRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/taskloop/rules/time_list_rule.rb

Constant Summary

Constants inherited from Rule

Rule::UNIT

Instance Attribute Summary collapse

Attributes inherited from Rule

#unit

Instance Method Summary collapse

Constructor Details

#initialize(unit, times) ⇒ TimeListRule

Returns a new instance of TimeListRule.



22
23
24
25
26
27
28
29
# File 'lib/taskloop/rules/time_list_rule.rb', line 22

def initialize(unit, times)
  super unit
  unless times != nil && times.length > 0
    raise ArgumentError, "times arguments need at least one value."
  end

  @times = times
end

Instance Attribute Details

#timesObject



8
9
10
# File 'lib/taskloop/rules/time_list_rule.rb', line 8

def times
  @times ||= []
end

Instance Method Details

#descObject



41
42
43
# File 'lib/taskloop/rules/time_list_rule.rb', line 41

def desc
  super + "; time_list: #{times.join(', ')}"
end

#is_conform_rule?(last_exec_time) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'lib/taskloop/rules/time_list_rule.rb', line 31

def is_conform_rule?(last_exec_time)
  current = Time.now
  result = false

  times_values.each do |time|
    result = result || (time.hour == current.hour && time.min == current.min)
  end
  return result
end

#times_valuesObject



12
13
14
15
16
17
18
19
20
# File 'lib/taskloop/rules/time_list_rule.rb', line 12

def times_values
  values = []
  times.each do |time|
    time_format = "%H:%M:%S"
    time_object = Time.strptime(time, time_format)
    values.push(time_object)
  end
  return values
end