Class: PDF::Reader::RegisterReceiver

### Home Classes Methods

### In Files

- lib/pdf/reader/register_receiver.rb

### Parent

Object

### Methods

- ::new
- #all
- #all_args
- #count
- #final_occurance_of
- #first_occurance_of
- #method_missing
- #respond_to?
- #series

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# PDF::Reader::RegisterReceiver

An example receiver that just records all callbacks generated by parsing a PDF file.

Useful for testing the contents of a file in an rspec/test-unit suite.

Usage:

    PDF::Reader.open("somefile.pdf") do |reader|
      receiver = PDF::Reader::RegisterReceiver.new
      reader.page(1).walk(receiver)
      callback = receiver.first_occurance_of(:show_text)
      callback[:args].first.should == "Hellow World"
    end

### Attributes

callbacks[RW]

### Public Class Methods

new() click to toggle source

    # File lib/pdf/reader/register_receiver.rb, line 24
    def initialize
      @callbacks = []
    end

### Public Instance Methods

all(methodname) click to toggle source

return the details for every time the specified callback was fired

    # File lib/pdf/reader/register_receiver.rb, line 42
    def all(methodname)
      callbacks.select { |cb| cb[:name] == methodname }
    end

all_args(methodname) click to toggle source

    # File lib/pdf/reader/register_receiver.rb, line 46
    def all_args(methodname)
      all(methodname).map { |cb| cb[:args] }
    end

count(methodname) click to toggle source

count the number of times a callback fired

    # File lib/pdf/reader/register_receiver.rb, line 37
    def count(methodname)
      callbacks.count { |cb| cb[:name] == methodname}
    end

final_occurance_of(methodname) click to toggle source

return the details for the final time the specified callback was fired

    # File lib/pdf/reader/register_receiver.rb, line 56
    def final_occurance_of(methodname)
      all(methodname).last
    end

first_occurance_of(methodname) click to toggle source

return the details for the first time the specified callback was fired

    # File lib/pdf/reader/register_receiver.rb, line 51
    def first_occurance_of(methodname)
      callbacks.find { |cb| cb[:name] == methodname }
    end

method_missing(methodname, *args) click to toggle source

    # File lib/pdf/reader/register_receiver.rb, line 32
    def method_missing(methodname, *args)
      callbacks << {:name => methodname.to_sym, :args => args}
    end

respond_to?(meth) click to toggle source

    # File lib/pdf/reader/register_receiver.rb, line 28
    def respond_to?(meth)
      true
    end

series(*methods) click to toggle source

return the first occurance of a particular series of callbacks

    # File lib/pdf/reader/register_receiver.rb, line 61
    def series(*methods)
      return nil if methods.empty?

      indexes = (0..(callbacks.size-1))
      method_indexes = (0..(methods.size-1))
      match = nil

      indexes.each do |idx|
        count = methods.size
        method_indexes.each do |midx|
          count -= 1 if callbacks[idx+midx] && callbacks[idx+midx][:name] == methods[midx]
        end
        if count == 0
          return callbacks[idx, methods.size]
        end
      end
      nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.