Sha256: 1a946672af2ca71d7ead5dd90605859de33bed72d634fade2f5618df930a0cdc

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

# coding: utf-8

module Thinreports
  module Core::Shape

    class TextBlock::Internal < Basic::BlockInternal
      format_delegators :multiple?

      def initialize(*args)
        super(*args)

        @reference = nil
        @formatter = nil

        @style = Style::Text.new(format)
        @style.accessible_styles.delete(:valign) unless multiple?
      end

      def style
        @style
      end

      def read_value
        if format.has_reference?
          @reference ||= parent.item(format.ref_id)
          @reference.value
        else
          super
        end
      end

      def write_value(val)
        if format.has_reference?
          warn 'The set value was not saved, ' +
               "Because '#{format.id}' has reference to '#{format.ref_id}'."
        else
          super
        end
      end

      def real_value
        if format_enabled?
          formatter.apply(read_value)
        else
          super
        end
      end

      def format_enabled(enabled)
        states[:format_enabled] = enabled
      end

      def format_enabled?
        return false if multiple?

        if states.key?(:format_enabled)
          states[:format_enabled]
        else
          !blank_value?(format.format_base) || format.has_format?
        end
      end

      def type_of?(type_name)
        type_name == TextBlock::TYPE_NAME || super
      end

    private

      def formatter
        @formatter ||= TextBlock::Formatter.setup(format)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinreports-0.9.1 lib/thinreports/core/shape/text_block/internal.rb
thinreports-0.9.0 lib/thinreports/core/shape/text_block/internal.rb