Module: ScheduleFu::Parser

Included in:
Finder
Defined in:
lib/schedule_fu/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(*args) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/schedule_fu/parser.rb', line 4

def parse(*args)
  raise ArgumentError unless args.length > 0
  if args.length == 1
    case args[0]
      when String then parse_dates(args[0])
      when Date then args[0]
      when Time then args[0]
      when Enumerable then args[0].map {|arg| parse(arg)}
      else raise ArgumentError, args[0].class.to_s
    end
  elsif args.length == 2
    (parse_date(args[0]) .. parse_date(args[1]))
  else
    args.map {|arg| parse(arg) }
  end
end

#parse_date(string) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/schedule_fu/parser.rb', line 21

def parse_date(string)
  unless string.nil?
    begin
      Date.parse(string)
    rescue; end
  end
end

#parse_dates(string) ⇒ Object



29
30
31
# File 'lib/schedule_fu/parser.rb', line 29

def parse_dates(string)
  parse_recurring_dates(string) || parse_specific_dates(string)
end