Class: ScheduledResource

Inherits:
Object
  • Object
show all
Defined in:
lib/scheduled_resource.rb,
lib/scheduled_resource/config.rb,
lib/scheduled_resource/helper.rb,
lib/scheduled_resource/version.rb,
lib/scheduled_resource/resource_use_block.rb

Overview

Using ScheduledResource as a module here for namespacing (in transition).

Defined Under Namespace

Modules: Helper Classes: Config, ResourceUseBlock

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, rid) ⇒ ScheduledResource

Instance methods



132
133
134
135
136
137
# File 'lib/scheduled_resource.rb', line 132

def initialize( kind, rid ) # :nodoc:
  # @tag = self.class.send( :compose_tag, kind, rid )
  @tag = self.class.compose_tag( kind, rid )
  @label = @title = nil
  self.class.rsrc_of_tag[@tag] = self
end

Instance Attribute Details

#labelObject



156
# File 'lib/scheduled_resource.rb', line 156

def label();     @label || @tag end

#titleObject



157
# File 'lib/scheduled_resource.rb', line 157

def title();     @title || @tag end

Class Method Details

.compose_tag(kind, sub_id) ⇒ Object



98
# File 'lib/scheduled_resource.rb', line 98

def compose_tag( kind, sub_id ); "#{kind}_#{sub_id}" end

.get_all_blocks(config, t1, t2, inc) ⇒ Object

(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 an rid; value is a list of blocks.



84
85
86
87
88
89
90
91
92
93
94
95
96
# 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

.make_resource_of_kind(klass, rid) ⇒ Object



100
101
102
103
# 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

Instance Method Details

#css_classes_for_rowObject

Returns

  • String - CSS classes automatically generated for the DOM row representing this SchedResource.



162
# File 'lib/scheduled_resource.rb', line 162

def css_classes_for_row(); "rsrcRow #{self.kind}row #{@tag}row #{self.kind}Row #{@tag}Row" end

#inspectObject

:nodoc:



151
152
153
# File 'lib/scheduled_resource.rb', line 151

def inspect() # :nodoc:
  "<#ScheduledResource \"#{@tag}\">"
end

#kindObject

Returns

  • String - The class name of the scheduled resource.



141
# File 'lib/scheduled_resource.rb', line 141

def kind()    @tag.sub( /_.*/, '' )          end

#sub_idObject

Returns

  • String - The rid (abstract id) of the ScheduledResource.



145
# File 'lib/scheduled_resource.rb', line 145

def sub_id()  @tag.sub( /.*_/, '' )          end

#to_sObject

:nodoc:



147
148
149
# File 'lib/scheduled_resource.rb', line 147

def to_s() # :nodoc:
  @tag
end