Sha256: 4712bce6bb3391cf57239cfff7cc76eb39a2efbdd7a3cd34f4132f4a69934c18

Contents?: true

Size: 827 Bytes

Versions: 6

Compression:

Stored size: 827 Bytes

Contents

require "PDFlib"
module FN
  module PDF
    class Struct < Hash
      attr_reader :pdf
      
      def initialize(debug = false)
        @pdf = PDFlib.new
        @debug = debug
      end  
      
      def assigns(node, value)
        self["{#{node[:assigns]}}"] = value
      end
      
      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fn_document-0.9.10 lib/fn/pdf/struct.rb
fn_document-0.9.9 lib/fn/pdf/struct.rb
fn_document-0.9.8 lib/fn/pdf/struct.rb
fn_document-0.9.7 lib/fn/pdf/struct.rb
fn_document-0.9.6 lib/fn/pdf/struct.rb
fn_document-0.9.4 lib/fn/pdf/struct.rb