module WorkingCalendar::CastHelper
Constants
- DAY_NAMES
Public Instance Methods
cast_date(date)
click to toggle source
# File lib/working_calendar/cast_helper.rb, line 6 def cast_date(date) case when date.is_a?(Date) then date when date.respond_to?(:to_date) then date.to_date when date.is_a?(String) then Date.parse(date) else raise(ArgumentError, "Invalid date #{date}") end end
cast_day_name(day_name)
click to toggle source
# File lib/working_calendar/cast_helper.rb, line 15 def cast_day_name(day_name) normalized_day_name = day_name.downcase.to_sym if DAY_NAMES.include? normalized_day_name normalized_day_name else raise ArgumentError, "Invalid day name #{day_name}" end end
cast_hours_ranges(hours_ranges)
click to toggle source
# File lib/working_calendar/cast_helper.rb, line 24 def cast_hours_ranges(hours_ranges) hours_ranges.each_with_object({}) do |(from_expression, to_expression), hash| from = Timing::HourMinutesSeconds.parse from_expression to = Timing::HourMinutesSeconds.parse to_expression raise ArgumentError, "Invalid range #{from - to}" if from >= to hash[from] = to end end