Sha256: c991a6c987d481003712451f939943c081a8edd981d80dcc309a1faaee853c20

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# coding: utf-8

module ThinReports
  module Core::Shape
    
    # @private
    # @abstract
    class Base::Internal
      extend ::Forwardable
      
      def self.format_delegators(*args)
        def_delegators :format, *args
      end
      private_class_method :format_delegators
      
      AVAILABLE_STYLES = [:fill, :stroke]
      
      attr_reader :parent
      attr_reader :format
      attr_accessor :attrs, :states
      
      def initialize(parent, format)
        @parent = parent
        @format = format
        
        @states = {}
        @attrs  = {}
        
        @finalized_attributes = nil
      end
      
      def attributes
        @finalized_attributes ||= (format.svg_attrs || {}).merge(attrs)
      end
      
      def copy(new_parent, &block)
        new_internal = self.class.new(new_parent, format)
        new_internal.attrs  = attrs.simple_deep_copy
        new_internal.states = states.simple_deep_copy
        
        block.call(new_internal) if block_given?
        new_internal
      end
      
      def switch_parent!(new_parent)
        @parent = new_parent
        self
      end
      
      def available_style?(style_name)
        AVAILABLE_STYLES.include?(style_name)
      end
      
      def type_of?(type_name)
        raise NotImplementedError
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinreports-0.6.0.pre3 lib/thinreports/core/shape/base/internal.rb