module Hue::Helpers
Public Instance Methods
numbers_to_times(numbers)
click to toggle source
# File lib/alexa_hue/hue/helpers.rb, line 8 def numbers_to_times(numbers) numbers.map!(&:in_numbers) numbers.map!(&:to_s) numbers.push("0") if numbers[1] == nil numbers = numbers.shift + ':' + (numbers[0].to_i + numbers[1].to_i).to_s numbers.gsub!(':', ':0') if numbers.split(":")[1].length < 2 numbers end
parse_time(string)
click to toggle source
# File lib/alexa_hue/hue/helpers.rb, line 17 def parse_time(string) string.sub!(" noon", " twelve in the afternoon") string.sub!("midnight", "twelve in the morning") time_modifier = string.downcase.scan(/(evening)|(night|tonight)|(afternoon)|(pm)|(a.m.)|(am)|(p.m.)|(morning)|(today)/).flatten.compact.first guess = Time.now.strftime('%H').to_i >= 12 ? "p.m." : "a.m." time_modifier = time_modifier.nil? ? guess : time_modifier day_modifier = string.scan(/(tomorrow)|(next )?(monday|tuesday|wednesday|thursday|friday|saturday|sunday)/).flatten.compact.join(' ') numbers_in_words = string.scan(Regexp.union((1..59).map(&:in_words))) set_time = numbers_to_times(numbers_in_words) set_time = Chronic.parse(day_modifier + ' ' + set_time + ' ' + time_modifier) end
set_time(string)
click to toggle source
# File lib/alexa_hue/hue/helpers.rb, line 29 def set_time(string) if string.scan(/ seconds?| minutes?| hours?| days?| weeks?/).any? set_time = string.partition("in").last.strip! set_time = Time.now + ChronicDuration.parse(string) elsif string.scan(/\d/).any? set_time = string.partition("at").last.strip! set_time = Chronic.parse(set_time) else set_time = string.partition("at").last.strip! set_time = parse_time(set_time) end end