Class TaskJuggler::Painter::Group
In: lib/taskjuggler/Painter/Group.rb
Parent: Object

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

Methods

method_missing   new   to_svg  

Included Modules

Primitives SVGSupport

Public Class methods

[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

Delegator to @originalSelf.

[Source]

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

Convert the Group into an XMLElement tree using SVG syntax.

[Source]

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

[Validate]