Sha256: 6f24765688270411a79b4199cf4c8820c1ce8b9ec03be2ab04106b54db288139

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module Thinreports
  module BasicReport
    module Core
      module Shape
        module TextBlock
          class Internal < Basic::BlockInternal
            format_delegators :multiple?

            attr_reader :style

            def initialize(*args)
              super(*args)

              @reference = nil
              @formatter = nil

              @style = Style::Text.new(format)
              @style.accessible_styles.delete(:valign) unless multiple?
            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?
              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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thinreports-0.14.2 lib/thinreports/basic_report/core/shape/text_block/internal.rb
thinreports-0.14.1 lib/thinreports/basic_report/core/shape/text_block/internal.rb
thinreports-0.14.0 lib/thinreports/basic_report/core/shape/text_block/internal.rb
thinreports-0.13.1 lib/thinreports/basic_report/core/shape/text_block/internal.rb
thinreports-0.13.0 lib/thinreports/basic_report/core/shape/text_block/internal.rb