pdf-forms 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 239cd68e0051c755b0197679386bbf0ce23f77da
4
- data.tar.gz: 0fcd9c4ff9c7ae8f9adbe3d0ad7976cfcaa63b0b
3
+ metadata.gz: dafa2a5c9130fc6e580251237c45d7c423f4e178
4
+ data.tar.gz: ade160fa891ee6d433f0d8baedb404eee2750d44
5
5
  SHA512:
6
- metadata.gz: d05df9821b1df134640b448ca9888b7e5926cef2fc7ad9193d26cc3d8579dd1c396e61c905ef7d326fdae4c3f70a0a52e7951d4ca54986469a80484fe3b2911d
7
- data.tar.gz: e2a3c1880c92aecbf6a4532dc5bd437c5a20cf3a7cda5c31dab4c75b815d18cb56160bb1df0d7c3a1015889283d51a10d2176aa300b0941d248e360e5f7eba1e
6
+ metadata.gz: de0909cb12fc43557003d02b6fc972ee2fad1916da68b318d52df36b3fa5bb3aabd7055d6c0e9744d6f0f92c4c74a731cc87fc4e5a36de96773a27c8958620ed
7
+ data.tar.gz: 8f0eadfcdd96afa187303644909c5db91de9c18771731aebd2a89cac98fa63ac13289b62c7e0677428879ad484a39098c1fd5ebb63f816b0295e7227b2e4a2bb
data/README.md CHANGED
@@ -23,7 +23,7 @@ unusual here.
23
23
 
24
24
  ```ruby
25
25
  require 'pdf_forms'
26
- fdf # PdfForms::Fdf.new :key #> 'value', :other_key #> 'other value'
26
+ fdf = PdfForms::Fdf.new :key => 'value', :other_key => 'other value'
27
27
  # use to_pdf_data if you just want the fdf data, without writing it to a file
28
28
  puts fdf.to_pdf_data
29
29
  # write fdf file
@@ -38,22 +38,22 @@ To generate XFDF instead of FDF instantiate `PdfForms::XFdf` instead of `PdfForm
38
38
  require 'pdf_forms'
39
39
 
40
40
  # adjust the pdftk path to suit your pdftk installation
41
- # add :data_format #> 'XFdf' option to generate XFDF instead of FDF when
41
+ # add :data_format => 'XFdf' option to generate XFDF instead of FDF when
42
42
  # filling a form (XFDF is supposed to have better support for non-western
43
43
  # encodings)
44
- # add :utf8_fields #> true in order to get UTF8 encoded field metadata (this
44
+ # add :utf8_fields => true in order to get UTF8 encoded field metadata (this
45
45
  # will use dump_data_fields_utf8 instead of dump_data_fields in the call to
46
46
  # pdftk)
47
- pdftk # PdfForms.new('/usr/local/bin/pdftk')
47
+ pdftk = PdfForms.new('/usr/local/bin/pdftk')
48
48
 
49
49
  # find out the field names that are present in form.pdf
50
50
  pdftk.get_field_names 'path/to/form.pdf'
51
51
 
52
52
  # take form.pdf, set the 'foo' field to 'bar' and save the document to myform.pdf
53
- pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', :foo #> 'bar'
53
+ pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', :foo => 'bar'
54
54
 
55
55
  # optionally, add the :flatten option to prevent editing of a filled out form
56
- pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', {:foo #> 'bar'}, :flatten #> true
56
+ pdftk.fill_form '/path/to/form.pdf', 'myform.pdf', {:foo => 'bar'}, :flatten => true
57
57
  ```
58
58
 
59
59
  ### Prior Art
@@ -2,7 +2,6 @@
2
2
 
3
3
  module PdfForms
4
4
  class Field
5
-
6
5
  # FieldType: Button
7
6
  # FieldName: Sprachoptionen_Inverssuche_Widerspruch
8
7
  # FieldFlags: 0
@@ -17,20 +16,33 @@ module PdfForms
17
16
  when /FieldStateOption:\s*(.*?)\s*$/
18
17
  (@options ||= []) << $1
19
18
  else
20
- if match = line.match(/^\s*(?<key>[^:]+):\s*(?<value>.*)$/)
21
- key = match[:key].to_s.strip
22
- value = match[:value].to_s
23
- var_name = key.gsub(/Field/, '').downcase
24
- unless self.respond_to?(var_name)
25
- self.class.send(:define_method, var_name.to_sym, Proc.new{ instance_variable_get("@#{var_name}".to_sym) } ) # in case new or unknown fields crop up...
26
- end
27
- instance_variable_set("@#{key.gsub(/Field/, '').downcase}".to_sym, value)
19
+ line.strip!
20
+ key, value = line.split(": ")
21
+ key.gsub!(/Field/, "")
22
+ key = key.split(/(?=[A-Z])/).map(&:downcase).join('_').split(":")[0]
23
+
24
+ instance_variable_set("@#{key}", value)
25
+
26
+ # dynamically add in fields that we didn't anticipate in ATTRS
27
+ unless self.respond_to?(key.to_sym)
28
+ proc = Proc.new { instance_variable_get("@#{key}".to_sym) }
29
+ self.class.send(:define_method, key.to_sym, proc)
28
30
  end
29
31
  end
30
32
  end
31
33
  end
34
+
35
+ def to_hash
36
+ hash = {}
37
+ ATTRS.each do |attribute|
38
+ hash[attribute] = self.send(attribute)
39
+ end
40
+
41
+ hash
42
+ end
32
43
 
33
44
  # Common Fields
34
- attr_reader :name, :type, :options, :flags, :justification, :value, :valuedefault
45
+ ATTRS = [:name, :type, :options, :flags, :justification, :value, :value_default, :name_alt, :max_length]
46
+ ATTRS.each {|attribute| attr_reader attribute}
35
47
  end
36
48
  end
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module PdfForms
4
- VERSION = '0.5.8'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Krämer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby frontend to the pdftk binary, including FDF and XFDF creation.
14
14
  Just pass your template and a hash of data to fill in.
@@ -40,12 +40,12 @@ require_paths:
40
40
  - lib
41
41
  required_ruby_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ">="
43
+ - - '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ">="
48
+ - - '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: 1.3.6
51
51
  requirements: []