Class: FN::PDF::Struct

Inherits:
Hash
  • Object
show all
Defined in:
lib/fn/pdf/struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug = false) ⇒ Struct

Returns a new instance of Struct.



7
8
9
10
# File 'lib/fn/pdf/struct.rb', line 7

def initialize(debug = false)
  @pdf = PDFlib.new
  @debug = debug
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a, &b) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fn/pdf/struct.rb', line 16

def method_missing(*a, &b)
  a.map! do |elem|
    case elem
    when Hash
      elem.inject([]) {|m, (k, v)| 
        m << "#{k}={#{v}}"
      }.join(" ")
    else
      elem
    end
  end
  begin
    # puts "command: #{a.inspect}"        if @debug
    @pdf.send(*a, &b)
  rescue Exception => e
    $stderr.puts("tried calling #{a.shift} with args: #{a.inspect}, state: #{inspect}")
    raise e
  end
end

Instance Attribute Details

#pdfObject (readonly)

Returns the value of attribute pdf.



5
6
7
# File 'lib/fn/pdf/struct.rb', line 5

def pdf
  @pdf
end

Instance Method Details

#assigns(node, value) ⇒ Object



12
13
14
# File 'lib/fn/pdf/struct.rb', line 12

def assigns(node, value)
  self["{#{node[:assigns]}}"] = value
end