Class: PdfForms::DataFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf_forms/data_format.rb

Direct Known Subclasses

Fdf, XFdf

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, options = {}) ⇒ DataFormat

Returns a new instance of DataFormat.



7
8
9
10
11
12
13
14
# File 'lib/pdf_forms/data_format.rb', line 7

def initialize(data = {}, options = {})
  @data = data
  @options = {
    :file => nil,
    :ufile => nil,
    :id => nil
  }.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/pdf_forms/data_format.rb', line 5

def options
  @options
end

Instance Method Details

#save_to(path) ⇒ Object

write fdf content to path



37
38
39
# File 'lib/pdf_forms/data_format.rb', line 37

def save_to(path)
  (File.open(path, 'wb') << to_fdf).close
end

#to_pdf_dataObject Also known as: to_fdf

generate PDF content in this data format



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pdf_forms/data_format.rb', line 17

def to_pdf_data
  pdf_data = header

  @data.each do |key, value|
    if Hash === value
      value.each do |sub_key, sub_value|
        pdf_data << field("#{key}_#{sub_key}", sub_value)
      end
    else
      pdf_data << field(key, value)
    end
  end

  pdf_data << footer
  return encode_data(pdf_data)
end