Class: CronInfo::DayOfWeekParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/cron_info/day_of_week_parser.rb

Instance Method Summary collapse

Methods inherited from Parser

#is_every_time_interval?, #is_numeric?, #is_range?, #is_word?, #is_word_range?, #parse, #parse_every_time_interval, #parse_range, #parse_single, #raise_out_of_range_error

Instance Method Details

#day_of_week_mappingsObject



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/cron_info/day_of_week_parser.rb', line 3

def day_of_week_mappings
  {
    "mon" => 1,
    "tue" => 2,
    "wed" => 3,
    "thu" => 4,
    "fri" => 5,
    "sat" => 6,
    "sun" => 7
  }
end

#labelObject



38
39
40
# File 'lib/cron_info/day_of_week_parser.rb', line 38

def label
  "day of week"
end

#max_valueObject



34
35
36
# File 'lib/cron_info/day_of_week_parser.rb', line 34

def max_value
  7
end

#min_valueObject



30
31
32
# File 'lib/cron_info/day_of_week_parser.rb', line 30

def min_value
  1
end

#parse_word(cron_string) ⇒ Object



23
24
25
26
27
28
# File 'lib/cron_info/day_of_week_parser.rb', line 23

def parse_word(cron_string)
  if day_of_week_mappings[cron_string.downcase] == nil
    raise "Invalid day of week argument #{cron_string}"
  end
  [day_of_week_mappings[cron_string.downcase]]
end

#parse_word_range(cron_string) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/cron_info/day_of_week_parser.rb', line 15

def parse_word_range(cron_string)
  first_word, last_word = cron_string.split("-")
  if day_of_week_mappings[first_word.downcase] == nil || day_of_week_mappings[last_word.downcase] == nil
    raise "Invalid day of week word range argument #{cron_string}"
  end
  (day_of_week_mappings[first_word.downcase]..day_of_week_mappings[last_word.downcase]).to_a
end