class TaskJuggler::Painter::Group

The Group can be used to group Elements together and define common attributes in a single place.

Public Class Methods

new(values) { |self| ... } click to toggle source
# File lib/taskjuggler/Painter/Group.rb, line 28
def initialize(values, &block)
  @attributes = [
    :fill, :font_family, :font_size, :stroke, :stroke_width
  ]
  values.each do |k, v|
    unless @attributes.include?(k)
      raise ArgumentError, "Unsupported attribute #{k}. " +
                           "Use one of #{@attributes.join(', ')}."
    end
  end

  @values = values
  @elements = []

  if block
    if block.arity == 1
      # This is the traditional case where self is passed to the block.
      # All Primitives methods now must be prefixed with the block
      # variable to call them.
      yield self
    else
      # In order to have the primitives easily available in the block,
      # we use instance_eval to switch self to this object. But this
      # makes the methods of the original self no longer accessible. We
      # work around this by saving the original self and using
      # method_missing to delegate the method call to the original self.
      @originalSelf = eval('self', block.binding)
      instance_eval(&block)
    end
  end
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source

Delegator to @originalSelf.

# File lib/taskjuggler/Painter/Group.rb, line 61
def method_missing(method, *args, &block)
  @originalSelf.send(method, *args, &block)
end
to_svg() click to toggle source

Convert the Group into an XMLElement tree using SVG syntax.

# File lib/taskjuggler/Painter/Group.rb, line 66
def to_svg
  XMLElement.new('g', valuesToSVG) do
    @elements.map { |el| el.to_svg }
  end
end