Sha256: 20b3a2e865df72062bcee1f53fd946c64ea5bdc0492118e90e383ebea9002d08

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

# coding: utf-8

module Thinreports
  module Core::Shape

    class PageNumber::Internal < Basic::Internal
      format_delegators :box

      def read_format
        states.key?(:format) ? states[:format] : format.default_format.dup
      end

      def reset_format
        states.delete(:format)
      end

      def write_format(format)
        states[:format] = format.to_s
      end

      def build_format(page_no, page_count)
        return '' if blank_value?(read_format)

        if start_page_number > 1
          page_no += start_page_number - 1
          page_count += start_page_number - 1
        end

        read_format.dup.tap do |f|
          f.gsub! '{page}', page_no.to_s
          f.gsub! '{total}', page_count.to_s
        end
      end

      def style
        @style ||= PageNumber::Style.new(format)
      end

      def for_report?
        blank_value?(format.target)
      end

      def type_of?(type_name)
        type_name == :pageno
      end

      def start_page_number
        for_report? ? parent.report.start_page_number : 1
      end
    end

    class PageNumber::Style < Style::Text
      accessible_styles.delete :valign
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinreports-0.8.2 lib/thinreports/core/shape/page_number/internal.rb
thinreports-0.8.1 lib/thinreports/core/shape/page_number/internal.rb
thinreports-0.8.0 lib/thinreports/core/shape/page_number/internal.rb