Class: PageTemplate::BlockCommand
- Defined in:
- lib/PageTemplate/commands.rb
Overview
BlockCommand provides a single interface to multiple Command objects. This should probably never be called by the designer or programmer, but by StackableCommands.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#add(command) ⇒ Object
Adds
command
to the end of the BlockCommand’s chain of Commands. -
#initialize ⇒ BlockCommand
constructor
A new instance of BlockCommand.
-
#length ⇒ Object
Returns the number of Commands held in this BlockCommand.
-
#output(namespace = nil) ⇒ Object
Calls Command#output(namespace) on each Command contained in this object.
-
#to_s ⇒ Object
Return Commands held, as a string.
Constructor Details
#initialize ⇒ BlockCommand
Returns a new instance of BlockCommand.
115 116 117 |
# File 'lib/PageTemplate/commands.rb', line 115 def initialize() @commandBlock = [] end |
Instance Method Details
#add(command) ⇒ Object
Adds command
to the end of the BlockCommand’s chain of Commands.
A TypeError is raised if the object being added is not a ((<Command>)).
133 134 135 136 137 138 |
# File 'lib/PageTemplate/commands.rb', line 133 def add(command) unless command.is_a?(Command) raise TypeError, 'BlockCommand.add: Attempt to add non-Command object' end @commandBlock << command end |
#length ⇒ Object
Returns the number of Commands held in this BlockCommand
125 126 127 |
# File 'lib/PageTemplate/commands.rb', line 125 def length @commandBlock.length end |
#output(namespace = nil) ⇒ Object
Calls Command#output(namespace) on each Command contained in this object. The output is returned as a single string. If no output is generated, returns an empty string.
143 144 145 |
# File 'lib/PageTemplate/commands.rb', line 143 def output(namespace = nil) @commandBlock.map{|x| x.output(namespace)}.join('') end |
#to_s ⇒ Object
Return Commands held, as a string
120 121 122 |
# File 'lib/PageTemplate/commands.rb', line 120 def to_s '[ Blocks: ' + @commandBlock.map{ |i| "[#{i.to_s}]" }.join(' ') + ']' end |