Class: TaskLoop::TimeListRule
- Defined in:
- lib/taskloop/rules/time_list_rule.rb
Constant Summary
Constants inherited from Rule
Instance Attribute Summary collapse
Attributes inherited from Rule
Instance Method Summary collapse
- #desc ⇒ Object
-
#initialize(unit, times) ⇒ TimeListRule
constructor
A new instance of TimeListRule.
- #is_conform_rule?(last_exec_time) ⇒ Boolean
- #times_values ⇒ Object
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
#times ⇒ Object
8 9 10 |
# File 'lib/taskloop/rules/time_list_rule.rb', line 8 def times @times ||= [] end |
Instance Method Details
#desc ⇒ Object
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
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_values ⇒ Object
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 |