Class: TaskLoop::SpecificRule

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

Returns a new instance of SpecificRule.



7
8
9
10
11
12
13
14
# File 'lib/taskloop/rules/specific_rule.rb', line 7

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

  @values = values
end

Instance Attribute Details

#valuesObject

Returns the value of attribute values.



5
6
7
# File 'lib/taskloop/rules/specific_rule.rb', line 5

def values
  @values
end

Instance Method Details

#descObject



53
54
55
# File 'lib/taskloop/rules/specific_rule.rb', line 53

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

#is_conform_rule?(last_exec_time) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/taskloop/rules/specific_rule.rb', line 32

def is_conform_rule?(last_exec_time)
  current = Time.now
  vals = values_values
  result = false
  case @unit
  when :year then
    result = vals.include?(current.year)
  when :month then
    result = vals.include?(current.month)
  when :week then
    result = vals.include?(current.wday)
  when :day then
    result = vals.include?(current.day)
  when :hour then
    result = vals.include?(current.hour)
  when :minute then
    result = vals.include?(current.min)
  end
  return result
end

#values_valuesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/taskloop/rules/specific_rule.rb', line 16

def values_values
  if @unit == :week
    return @values.map { |key| Task::WEEK[key] }
  end

  if @unit == :day
    return @values.map { |key| Task::DAY[key] }
  end

  if @unit == :month
    return @values.map { |key| Task::MONTH[key] }
  end

  return @values
end