Class: TaskLoop::DateListRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/taskloop/rules/date_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, dates) ⇒ DateListRule

Returns a new instance of DateListRule.



21
22
23
24
25
26
27
# File 'lib/taskloop/rules/date_list_rule.rb', line 21

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

Instance Attribute Details

#datesObject



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

def dates
  @dates ||= []
end

Instance Method Details

#dates_valuesObject



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

def dates_values
  values = []
  dates.each do |date|
    date_format = "%Y-%m-%d"
    date_object = Time.strptime(date, date_format)
    values.push(date_object)
  end
  return values
end

#descObject



39
40
41
# File 'lib/taskloop/rules/date_list_rule.rb', line 39

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

#is_conform_rule?(last_exec_time) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
# File 'lib/taskloop/rules/date_list_rule.rb', line 29

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

  dates_values.each do |date|
    result = result || (date.year == current.year && date.month == current.month && date.day == current.day)
  end
  return result
end