Class: Cronex::DayOfWeekDescription

Inherits:
Description show all
Defined in:
lib/cronex/description/day_of_week.rb

Instance Attribute Summary

Attributes inherited from Description

#options, #resources

Instance Method Summary collapse

Methods inherited from Description

#initialize, #plural, #segment_description, #special_chars

Constructor Details

This class inherits a constructor from Cronex::Description

Instance Method Details

#between_description_format(expression) ⇒ Object



30
31
32
# File 'lib/cronex/description/day_of_week.rb', line 30

def between_description_format(expression)
  ', ' + resources.get('between_weekday_description_format')
end

#description_format(expression) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cronex/description/day_of_week.rb', line 34

def description_format(expression)
  if expression.include?('#')
    dow_num = expression.split('#').last
    days = Hash[%w(1 2 3 4 5).zip(%w(first second third fourth fifth))]
    dow_desc = days[dow_num]
    dow_desc = dow_desc ? resources.get(dow_desc) : ''
    ', ' + resources.get('on_the_day_of_the_month').gsub(/{{.*}}/, dow_desc)
  elsif expression.include?('L')
    ', ' + resources.get('on_the_last_of_the_month')
  else
    ', ' + resources.get('only_on')
  end
end

#interval_description_format(expression) ⇒ Object



26
27
28
# File 'lib/cronex/description/day_of_week.rb', line 26

def interval_description_format(expression)
  format(', ' + resources.get('interval_description_format'), expression)
end

#single_item_description(expression) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cronex/description/day_of_week.rb', line 3

def single_item_description(expression)
  exp = expression
  if expression.include?('#')
    exp = expression.partition('#').first
  elsif expression.include?('L')
    exp = exp.gsub('L', '')
  end

  if Cronex::Utils.number?(exp)
    dow_num = Cronex::Utils.integer(exp)
    zero_based_dow = options[:zero_based_dow]
    invalid_dow = !zero_based_dow && dow_num <= 1
    if invalid_dow || (zero_based_dow && dow_num == 0)
      return resources.get(Cronex::Utils.day_of_week_name(0).downcase) # or 7 as in java DateTime().withDayOfWeek(7) for Sunday
    elsif !zero_based_dow
      dow_num -= 1
    end
    return resources.get(Cronex::Utils.day_of_week_name(dow_num).downcase)
  else
    return Date.parse(exp.capitalize).strftime('%A')
  end
end

#starting_description_format(expression) ⇒ Object



48
49
50
# File 'lib/cronex/description/day_of_week.rb', line 48

def starting_description_format(expression)
  resources.get('starting') + ' ' + resources.get('on_x')
end