Module: ScheduledResource::Helper
- Defined in:
- lib/scheduled_resource/helper.rb
Instance Method Summary collapse
- #default_time_param ⇒ Object
-
#ensure_schedule_config ⇒ Object
fka :config_from_yaml : :ensure_config.
-
#get_data_for_time_span ⇒ Object
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’.
-
#json_adjustments ⇒ Object
Always send starttime/endtime attributes as Integer values (UTC) – they are used to size and place the use_blocks.
- #max_time ⇒ Object
- #min_time ⇒ Object
- #set_schedule_query_params(p = params) ⇒ Object
Instance Method Details
#default_time_param ⇒ Object
11 12 13 14 |
# 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 ⇒ Object
fka :config_from_yaml : :ensure_config
6 7 8 9 |
# 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 ⇒ Object
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
29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
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).
49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
43 |
# File 'lib/scheduled_resource/helper.rb', line 43 def max_time; @config.time_range_max.to_i end |
#min_time ⇒ Object
42 |
# File 'lib/scheduled_resource/helper.rb', line 42 def min_time; @config.time_range_min.to_i end |
#set_schedule_query_params(p = params) ⇒ Object
16 17 18 19 20 |
# 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 |