1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/alexa_hue/fix_schedule_syntax.rb', line 1
def fix_schedule_syntax(string)
sub_time = string.match(/time \d{2}:\d{2}/)
sub_duration = string.match(/schedule PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/)
if sub_time
sub_time = sub_time.to_s
string.slice!(sub_time).strip
string << " #{sub_time}"
string.sub!("time", "schedule at")
end
if sub_duration
sub_duration = sub_duration.to_s
string.slice!(sub_duration).strip
sub_duration = ChronicDuration.parse(sub_duration.split(' ').last)
string << " schedule in #{sub_duration} seconds"
end
string.strip if string
end
|