3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/crony/presenters/time_presenter.rb', line 3
def self.parse(minute, hour)
minute = Formatters::MinuteFormatter.new(Parser.parse(minute))
hour = Formatters::HourFormatter.new(Parser.parse(hour))
case [minute, hour].map(&:sym).join('')
when /[ev]e/ then minute.format
when 're' then "every hour from xx:#{minute.start.two_digits} to xx:#{minute.stop.two_digits}"
when 'ss' then "#{time(hour.single_element, minute.single_element)}"
when 'sc' then "#{hour.collection.map{|h| time(h, minute.single_element)}.to_sentence}"
when 'us' then "#{minute.format(false)} between #{time_range(hour.single_element, minute.start, hour.single_element, 59)}"
when 'uc' then "#{minute.format(false)} between #{hour.collection.map{|h| time_range(h, minute.start, h, 59)}.to_sentence}"
when /c[cs]/ then "#{hour.collection.map{|h| minute.collection.map{|m| time(h, m)}}.flatten.to_sentence}"
when /[ucsfr]r/ then ("%s of every hour between %s" % [minute.format, hour.format]).squeeze(' ')
when /^[fr][cs]$/ then "#{minute.format(hour.collection)}"
when /^.[rsc]$/ then ("%s between %s" % [minute.format, hour.format]).squeeze(' ')
else ("%s of %s" % [minute.format, hour.format]).squeeze(' ')
end
end
|