Class: PageTemplate::BlockCommand

Inherits:
Command
  • Object
show all
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

Template

Instance Attribute Summary

Attributes inherited from Command

#called_as

Instance Method Summary collapse

Constructor Details

#initializeBlockCommand

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

#lengthObject

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_sObject

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