class HolidayList::Params
Params: Munges google calendar api request parameters
Attributes
key[R]
Public Class Methods
new(key, time_options = {})
click to toggle source
# File lib/holiday_list/params.rb, line 10 def initialize(key, time_options = {}) @key = key @options = time_options validate_options! end
Public Instance Methods
params_hash()
click to toggle source
# File lib/holiday_list/params.rb, line 21 def params_hash { key: key, orderBy: order_by, singleEvents: single_events, timeMin: time_min, timeMax: time_max } end
to_s()
click to toggle source
# File lib/holiday_list/params.rb, line 17 def to_s params_hash.to_query end
Private Instance Methods
order_by()
click to toggle source
# File lib/holiday_list/params.rb, line 41 def order_by 'startTime' end
single_events()
click to toggle source
# File lib/holiday_list/params.rb, line 45 def single_events true end
time_max()
click to toggle source
# File lib/holiday_list/params.rb, line 37 def time_max @time_max ||= @options.fetch('stop') { DateTime.now.next_year.new_offset(0) } end
time_min()
click to toggle source
# File lib/holiday_list/params.rb, line 33 def time_min @time_min ||= @options.fetch('start') { DateTime.now.new_offset(0) } end
validate_options!()
click to toggle source
# File lib/holiday_list/params.rb, line 49 def validate_options! message = 'Start and end dates must be valid DateTime objects that'\ ' occur sequentially' fail ArgumentError, message if [time_min, time_max].any? do |time| time.class != DateTime end fail ArgumentError, message if time_min > time_max end