Sha256: bb2e11d0b75f8a9e326d5ba55fcbdf7f0bcc2ff6763065e6d8dd2ce98eaf71c1

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

# coding: utf-8

class PDF::Reader

  # DEPRECATED: this class was deprecated in version 0.11.0 and will
  #             eventually be removed
  class AbstractStrategy # :nodoc:

    def initialize(ohash, receivers, options = {})
      @ohash, @options = ohash, options
      if receivers.is_a?(Array)
        @receivers = receivers
      else
        @receivers = [receivers]
      end
    end

    private

    def options
      @options || {}
    end

    # calls the name callback method on the receiver class with params as the arguments
    #
    def callback (name, params=[])
      @receivers.each do |receiver|
        receiver.send(name, *params) if receiver.respond_to?(name)
      end
    end

    # strings outside of page content should be in either PDFDocEncoding or UTF-16.
    def decode_strings(obj)
      case obj
      when String then
        if obj[0,2].unpack("C*").slice(0,2) == [254,255]
          PDF::Reader::Encoding.new(:UTF16Encoding).to_utf8(obj[2, obj.size])
        else
          PDF::Reader::Encoding.new(:PDFDocEncoding).to_utf8(obj)
        end
      when Hash   then obj.each { |key,val| obj[key] = decode_strings(val) }
      when Array  then obj.collect { |item| decode_strings(item) }
      else
        obj
      end
    end

    def info
      ohash.object(trailer[:Info])
    end

    def info?
      info ? true : false
    end

    def ohash
      @ohash
    end

    def pages
      ohash.object(root[:Pages])
    end

    def pages?
      pages ? true : false
    end

    def root
      ohash.object(trailer[:Root])
    end

    def root?
      root ? true : false
    end

    def trailer
      ohash.trailer
    end

  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
pdf-reader-1.4.0 lib/pdf/reader/abstract_strategy.rb
panjiva-pdf-reader-1.3.0 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.3.3 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.3.2 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.3.1 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.3.0 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.2.0 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.1.1 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.1.0 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.0.0 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.0.0.rc1 lib/pdf/reader/abstract_strategy.rb
pdf-reader-1.0.0.beta1 lib/pdf/reader/abstract_strategy.rb
pdf-reader-0.12.0.alpha lib/pdf/reader/abstract_strategy.rb
fireinc-pdf-reader-0.11.0 lib/pdf/reader/abstract_strategy.rb
fireinc-pdf-reader-0.11.0.alpha lib/pdf/reader/abstract_strategy.rb
pdf-reader-0.11.0.alpha lib/pdf/reader/abstract_strategy.rb