module ScheduledResource::Helper
Public Instance Methods
default_time_param()
click to toggle source
# File lib/scheduled_resource/helper.rb, line 11 def default_time_param t_now = Time.now t_now.change :min => (t_now.min/15) * 15 end
ensure_schedule_config()
click to toggle source
# File lib/scheduled_resource/helper.rb, line 6 def ensure_schedule_config # fka :config_from_yaml : :ensure_config meth = params[:reset] ? :from_base : :ensure @config = ScheduledResource::Config.send( meth, session ) end
get_data_for_time_span()
click to toggle source
Set up instance variables for render templates or returned json
params: @t1: time-inverval start @t2: time-inverval end @inc: incremental update? One of: nil, 'lo', 'hi' creates: @rsrcs ordered resource list @blockss: lists of use-blocks, keyed by resource
# File lib/scheduled_resource/helper.rb, line 29 def get_data_for_time_span() set_schedule_query_params @t1 = Time.at(@t1.to_i) @t2 = Time.at(@t2.to_i) @rsrcs = @config.resource_list # ScheduledResource.resource_list @blockss = ScheduledResource.get_all_blocks(@config, @t1, @t2, @inc) json_adjustments end
json_adjustments()
click to toggle source
Always send starttime/endtime attributes as Integer values (UTC) – they are used to size and place the use_blocks. Timezone is configured separately in the ZTime* classes (config/resource_schedule.yml).
# File lib/scheduled_resource/helper.rb, line 49 def json_adjustments @blockss.each do |rsrc, blocks| blocks.each do |block| block.starttime = block.starttime.to_i block.endtime = block.endtime.to_i end end @blockss['meta'] = { rsrcs: @rsrcs, min_time: min_time, max_time: max_time, t1: @t1.to_i, t2: @t2.to_i, inc: @inc, } end
max_time()
click to toggle source
# File lib/scheduled_resource/helper.rb, line 43 def max_time; @config.time_range_max.to_i end
min_time()
click to toggle source
# File lib/scheduled_resource/helper.rb, line 42 def min_time; @config.time_range_min.to_i end
set_schedule_query_params(p = params)
click to toggle source
# File lib/scheduled_resource/helper.rb, line 16 def set_schedule_query_params(p = params) @t1 = p[:t1] || default_time_param @t2 = p[:t2] || @t1 + @config.visible_time # ScheduledResource.visible_time @inc= p[:inc] end