class ScheduledResource
A “scheduled resource” is something that can be used for one thing at a time.
Example: A Room (resource) is scheduled for a meeting (resource use block) titled “Weekly Staff Meeting” tomorrow from 9am to 11am.
Class ScheduledResource
manages class names, id’s and labels for a schedule. An instance ties together:
1. A resource class (eg Room), 2. An id (string), and 3. Strings / html snippets (eg, label, title) for the DOM.
The id (2 above) is used to
a) select a resource instance and
b) select instances of the resource use block class (eg Meeting).
The id may be a database id but need not be. It is used by class methods get_all_blocks()
of model use-block classes. Not tying this to a database id allows a little extra flexibility in configuration.
Items 1 and 2 are are combined (with a ‘_’) to form “tags” (ids) for the DOM.
See also: ResourceUseBlock
, Config
.
When queried with an array of ids and a time interval, the class method get_all_blocks(ids, t1, t2)
of a resource use model returns a list of “use blocks”, each with a starttime, endtime and descriptions of that use.
This method invokes that method on each of the resource use classes. It returns a hash where:
Key is a Resource (rsrc); Value is an array of use-block instances (rubs).
Using ScheduledResource
as a module here for namespacing (in transition).
Using ScheduledResource
as a module here for namespacing (in transition).
Constants
- VERSION
Attributes
Public Class Methods
# File lib/scheduled_resource.rb, line 98 def compose_tag( kind, sub_id ); "#{kind}_#{sub_id}" end
(ScheduledResource
protocol) Returns a hash where each key is an rid
and the value is an array of resource use blocks in the interval t1...t2
, ordered by starttime
.
What in means depends on inc. If inc(remental) is false, the client is building the interval from scratch. If “hi”, it is an addition to an existing interval on the high side. Similarly for “lo”. This is to avoid re-transmitting blocks that span the current time boundaries on the client.
Here the resource is a channel and the use blocks are programs.
Parameters¶ ↑
-
config
- A configuration instance. -
t1
- Start time. -
t2
- End time. -
inc
- One of nil, “lo”, “hi” (See above).
Returns¶ ↑
-
Hash
- Each key is anrid
; value is a list of blocks.
# File lib/scheduled_resource.rb, line 84 def get_all_blocks(config, t1, t2, inc) blockss = {} config.rsrcs_by_kind.each do |kind, rsrcs| rub_class = config.block_class_for_resource_name kind rids = rsrcs.map{ |r| r.sub_id } ru_blkss = rub_class.get_all_blocks rids, t1, t2, inc add_rubs_of_kind kind, ru_blkss, blockss end blockss end
# File lib/scheduled_resource.rb, line 100 def make_resource_of_kind( klass, rid ) klass = klass.constantize if klass.is_a? String # ToDo: Trim this. get_for( klass.name, rid ) end
Private Class Methods
# File lib/scheduled_resource.rb, line 118 def add_rubs_of_kind( kind, ru_blkss, blockss ) ru_blkss.each do |rid, blks| rsrc = get_for( kind, rid ) rubs = blks.map{ |blk| ResourceUseBlock.new rsrc, blk } blockss[ rsrc ] = rubs end end
A caching one-of-each-sort constructor.
Parameters¶ ↑
-
kind
- Class name (string) of a scheduled resource. -
rid
- Id (string), selecting a resource instance. The two are combined and used as a unique tag in the DOM as id and class attributes as well as in server code.
# File lib/scheduled_resource.rb, line 112 def get_for( kind, rid ) tag = compose_tag( kind, rid ) # config[:rsrc_of_tag][ tag ] || self.new( kind, rid ) rsrc_of_tag[ tag ] || new( kind, rid ) end
Public Instance Methods
# File lib/scheduled_resource.rb, line 156 def label(); @label || @tag end
Returns¶ ↑
-
String
- Therid
(abstract id) of theScheduledResource
.
# File lib/scheduled_resource.rb, line 145 def sub_id() @tag.sub( /.*_/, '' ) end
# File lib/scheduled_resource.rb, line 157 def title(); @title || @tag end