lib/pdf_ravager/template.rb in pdf_ravager-0.1.0 vs lib/pdf_ravager/template.rb in pdf_ravager-0.2.0

- old
+ new

@@ -6,14 +6,24 @@ require 'pdf_ravager/fieldsets/radio_group' require 'pdf_ravager/ravager' if RUBY_PLATFORM =~ /java/ module PDFRavager class Template - attr_reader :name, :fields + attr_reader :name, :strategy + attr_accessor :fields - def initialize(name=nil) - @name, @fields = name, [] + def initialize(opts={}) + opts = {:name => opts} if opts.respond_to?(:to_sym) + unless opts[:name].nil? + warn "[DEPRECATION] Passing a name to `PDFRavager::Template.new` " + + "is deprecated and will be removed in 1.0.0" + end + @name, @strategy = opts[:name], (opts[:strategy] || :smart) + unless [:smart, :acro_forms, :xfa].include?(@strategy) + raise "Bad strategy '#{@strategy}'" + end + @fields = [] yield self if block_given? end def text(name, value) @fields << PDFRavager::Fields::Text.new(name, value) @@ -43,10 +53,10 @@ PDFRavager::Fieldsets::RadioGroup.new(self, group_name, &blk) end if RUBY_PLATFORM =~ /java/ def ravage(file, opts={}) - PDFRavager::Ravager.ravage(self, opts.merge({:in_file => file})) + PDFRavager::Ravager.new(self, opts.merge({:in_file => file})).ravage end else def ravage(file, opts={}) raise "You can only ravage PDFs using JRuby, not #{RUBY_PLATFORM}!" end