Sha256: e52cdca9a103ae8f8453af7d15aa0fe71b46b15ed0deaf53b19e230a721cfc4e

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

# coding: utf-8

class PDF::Reader

  class AbstractStrategy # :nodoc:

    def initialize(ohash, receiver, options = {})
      @ohash, @receiver, @options = ohash, receiver, options
    end

    private

    def options
      @options || {}
    end

    # calls the name callback method on the receiver class with params as the arguments
    #
    def callback (name, params=[])
      receiver.send(name, *params) if receiver.respond_to?(name)
    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 receiver
      @receiver
    end

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

    def root?
      root ? true : false
    end

    def trailer
      ohash.trailer
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pdf-reader-0.9.3 lib/pdf/reader/abstract_strategy.rb
pdf-reader-0.9.2 lib/pdf/reader/abstract_strategy.rb
pdf-reader-0.9.1 lib/pdf/reader/abstract_strategy.rb
pdf-reader-0.9.0 lib/pdf/reader/abstract_strategy.rb