Class: Crony::Formatters::DayOfWeekFormatter

Inherits:
CronStruct
  • Object
show all
Defined in:
lib/crony/formatters/day_of_week_formatter.rb

Constant Summary collapse

DAYS =
%w{ Sunday Monday Tuesday Wednesday Thursday Friday Saturday }
CRON_DAYS =
%w{ sun mon tue wed thu fri sat }

Instance Method Summary collapse

Methods inherited from CronStruct

#collection?, #every?, #format, #frequency?, #range?, #single_element, #single_element?, #unbounded_range?

Instance Method Details

#c(weekdays = collection) ⇒ Object



21
22
23
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 21

def c(weekdays=collection)
  "every #{weekdays.map{|weekday| get_weekday(weekday)}.to_sentence}"
end

#eObject



25
26
27
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 25

def e
  ""
end

#get_weekday(day) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 13

def get_weekday(day)
  if day =~ /[a-z]/i
    DAYS[CRON_DAYS.index(day.downcase)]
  else
    DAYS[day.to_i]
  end
end

#lObject



29
30
31
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 29

def l
  "the last #{get_weekday(single_element)}"
end

#nObject



33
34
35
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 33

def n
  "the #{nth_week.ordinal} #{get_weekday(single_element)}"
end

#rObject



37
38
39
40
41
42
43
44
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 37

def r
  if self.start =~ /[a-z]/i
    start, stop = [self.start, self.stop].map{|s| CRON_DAYS.index(s.downcase)}
  else
    start, stop = [self.start, self.stop].map(&:to_i)
  end
  c(Array(start.to_i..stop.to_i))
end

#sObject



46
47
48
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 46

def s
  "every #{get_weekday(single_element)}"
end

#symObject



7
8
9
10
11
# File 'lib/crony/formatters/day_of_week_formatter.rb', line 7

def sym
  return 'l' if !!last
  return 'n' if !!nth_week
  super
end