Class: PdfForms::DataFormat
- Inherits:
-
Object
- Object
- PdfForms::DataFormat
- Defined in:
- lib/pdf_forms/data_format.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(data = {}, options = {}) ⇒ DataFormat
constructor
A new instance of DataFormat.
-
#save_to(path) ⇒ Object
write fdf content to path.
-
#to_pdf_data ⇒ Object
(also: #to_fdf)
generate PDF content in this data format.
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 = {}, = {}) @data = data @options = { :file => nil, :ufile => nil, :id => nil }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/pdf_forms/data_format.rb', line 5 def @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_data ⇒ Object 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 << return encode_data(pdf_data) end |