Class: PDF::Reader::RegisterReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/register_receiver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegisterReceiver

Returns a new instance of RegisterReceiver



6
7
8
# File 'lib/pdf/reader/register_receiver.rb', line 6

def initialize
  @callbacks = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodname, *args) ⇒ Object



14
15
16
# File 'lib/pdf/reader/register_receiver.rb', line 14

def method_missing(methodname, *args)
  callbacks << {:name => methodname.to_sym, :args => args}
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks



4
5
6
# File 'lib/pdf/reader/register_receiver.rb', line 4

def callbacks
  @callbacks
end

Instance Method Details

#all(methodname) ⇒ Object

return the details for every time the specified callback was fired



26
27
28
29
30
31
32
# File 'lib/pdf/reader/register_receiver.rb', line 26

def all(methodname)
  ret = []
  callbacks.each do |cb|
    ret << cb if cb[:name] == methodname
  end
  return ret
end

#count(methodname) ⇒ Object

count the number of times a callback fired



19
20
21
22
23
# File 'lib/pdf/reader/register_receiver.rb', line 19

def count(methodname)
  counter = 0
  callbacks.each { |cb| counter += 1 if cb[:name] == methodname}
  return counter
end

#final_occurance_of(methodname) ⇒ Object

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



43
44
45
46
47
48
49
# File 'lib/pdf/reader/register_receiver.rb', line 43

def final_occurance_of(methodname)
  returnme = nil
  callbacks.each do |cb|
    returnme = cb if cb[:name] == methodname
  end
  return returnme
end

#first_occurance_of(methodname) ⇒ Object

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



35
36
37
38
39
40
# File 'lib/pdf/reader/register_receiver.rb', line 35

def first_occurance_of(methodname)
  callbacks.each do |cb|
    return cb if cb[:name] == methodname
  end
  return nil
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/pdf/reader/register_receiver.rb', line 10

def respond_to?(meth)
  true
end

#series(*methods) ⇒ Object

return the first occurance of a particular series of callbacks



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pdf/reader/register_receiver.rb', line 52

def series(*methods)
  return nil if methods.empty?

  indexes = (0..(callbacks.size-1-methods.size))
  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][:name] == methods[midx]
    end
    match = idx and break if count == 0
  end

  if match 
    return callbacks[match, methods.size]
  else
    return nil
  end
end