Class: Crony::Formatters::MonthFormatter

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

Constant Summary collapse

MONTHS =
%w{ January February March April May June July August September October November December }
CRON_MONTHS =
%w{ jan feb mar apr may jun jul aug sep oct nov dec }

Instance Method Summary collapse

Methods inherited from CronStruct

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

Instance Method Details

#cObject



19
20
21
# File 'lib/crony/formatters/month_formatter.rb', line 19

def c
  collection.map{|month| get_month(month)}.to_sentence
end

#eObject



23
24
25
# File 'lib/crony/formatters/month_formatter.rb', line 23

def e
  "every month"
end

#fObject Also known as: u



27
28
29
# File 'lib/crony/formatters/month_formatter.rb', line 27

def f
  "every #{frequency.ordinal} month #{range}"
end

#get_month(month) ⇒ Object



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

def get_month(month)
  if month =~ /[a-z]/i
    MONTHS[CRON_MONTHS.index(month.downcase)]
  else
    MONTHS[month.to_i - 1]
  end
end

#rObject



31
32
33
# File 'lib/crony/formatters/month_formatter.rb', line 31

def r
  "every month #{range}"
end

#rangeObject



15
16
17
# File 'lib/crony/formatters/month_formatter.rb', line 15

def range
  "from #{s(start)} to #{s(stop)}"
end

#s(month = single_element) ⇒ Object



35
36
37
# File 'lib/crony/formatters/month_formatter.rb', line 35

def s(month=single_element)
  get_month(month)
end

#vObject



41
42
43
# File 'lib/crony/formatters/month_formatter.rb', line 41

def v
  "every #{frequency.ordinal} month"
end