Class: AudioGlue::Template
- Inherits:
-
Object
- Object
- AudioGlue::Template
- Extended by:
- Forwardable
- Defined in:
- lib/audio_glue/template.rb,
lib/audio_glue/template/head_context.rb
Overview
Represents an audio template. Every particular template is a subclass of Template. Quite often the classes can be anonymous. (That’s why inspect
is redefined to provide more information.)
The Template class owns format
, rate
, channels
, and also a block used to create an SnippetPacket (“render”, in terms of the view templates).
A Template instance differs from the Template class. It has instance variables, that can be used in the body
block.
Defined Under Namespace
Classes: HeadContext
Class Attribute Summary collapse
-
.body_proc ⇒ Object
Returns the value of attribute body_proc.
-
.channels ⇒ Object
Returns the value of attribute channels.
-
.format ⇒ Object
Returns the value of attribute format.
-
.path ⇒ Object
Returns the value of attribute path.
-
.rate ⇒ Object
Returns the value of attribute rate.
Class Method Summary collapse
-
.body { ... } ⇒ void
Process the
body
block in a.glue
template. -
.head { ... } ⇒ void
Process the
head
block in a.glue
template. -
.inspect ⇒ String
Redefine the
inspect
method to provide more information when the template is an anonymous class.
Instance Method Summary collapse
-
#build_snippet_packet ⇒ AudioGlue::SnippetPacket
Execute the body of the template to build a snippet packet.
-
#initialize(variables = {}) ⇒ Template
constructor
A new instance of Template.
-
#inspect ⇒ String
Redefine
inspect
to provide more information if the class of the template object is anonymous.
Constructor Details
#initialize(variables = {}) ⇒ Template
Returns a new instance of Template.
84 85 86 87 88 |
# File 'lib/audio_glue/template.rb', line 84 def initialize(variables = {}) variables.each do |var, value| instance_variable_set("@#{var}", value) end end |
Class Attribute Details
.body_proc ⇒ Object
Returns the value of attribute body_proc.
44 45 46 |
# File 'lib/audio_glue/template.rb', line 44 def body_proc @body_proc end |
.channels ⇒ Object
Returns the value of attribute channels.
44 45 46 |
# File 'lib/audio_glue/template.rb', line 44 def channels @channels end |
.format ⇒ Object
Returns the value of attribute format.
44 45 46 |
# File 'lib/audio_glue/template.rb', line 44 def format @format end |
.path ⇒ Object
Returns the value of attribute path.
44 45 46 |
# File 'lib/audio_glue/template.rb', line 44 def path @path end |
.rate ⇒ Object
Returns the value of attribute rate.
44 45 46 |
# File 'lib/audio_glue/template.rb', line 44 def rate @rate end |
Class Method Details
.body { ... } ⇒ void
This method returns an undefined value.
Process the body
block in a .glue
template.
63 64 65 |
# File 'lib/audio_glue/template.rb', line 63 def self.body(&block) self.body_proc = block end |
.head { ... } ⇒ void
This method returns an undefined value.
Process the head
block in a .glue
template.
53 54 55 |
# File 'lib/audio_glue/template.rb', line 53 def self.head(&block) HeadContext.new(self).instance_eval(&block) end |
.inspect ⇒ String
Redefine the inspect
method to provide more information when the template is an anonymous class.
71 72 73 74 75 76 77 78 79 |
# File 'lib/audio_glue/template.rb', line 71 def self.inspect if self.name super else info = "<AudioGlue::Template(class)" info << " path=#{path.inspect}" if path info << ">" end end |
Instance Method Details
#build_snippet_packet ⇒ AudioGlue::SnippetPacket
Execute the body of the template to build a snippet packet.
93 94 95 96 97 |
# File 'lib/audio_glue/template.rb', line 93 def build_snippet_packet @__packet__ = SnippetPacket.new(format, rate, channels) instance_eval(&body_proc) @__packet__ end |
#inspect ⇒ String
Redefine inspect
to provide more information if the class of the template object is anonymous.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/audio_glue/template.rb', line 103 def inspect if self.class.name super else info = "<AudioGlue::Template" info << "(path=#{path.inspect})" if path instance_variables.each do |var| info << " #{var}=" info << instance_variable_get(var).inspect end info << ">" end end |