Class: PdftkForms::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/pdftk_forms/field.rb

Overview

Represents a fillable form field on a particular PDF

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Field

Returns a new instance of Field.



7
8
9
# File 'lib/pdftk_forms/field.rb', line 7

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/pdftk_forms/field.rb', line 5

def attributes
  @attributes
end

Class Method Details

.alias_attribute(method_name, attribute_name) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/pdftk_forms/field.rb', line 49

def self.alias_attribute method_name, attribute_name
  define_method(method_name) do
    attributes[attribute_name]
  end
  define_method("#{method_name}=") do |value|
    attributes[attribute_name] = value
  end
end

Instance Method Details

#check_box?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/pdftk_forms/field.rb', line 27

def check_box?
  self.type == 'Button' && !push_button? && !radio_button?
end

#field_typeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pdftk_forms/field.rb', line 31

def field_type
  if self.type == 'Button'
    if push_button?
      'push_button'
    elsif radio_button?
      'radio_button'
    else
      'check_box'
    end
  elsif self.type == 'Text'
    multiline? ? 'text_area' : 'text_field'
  elsif self.type == 'Choice'
    'select'
  else
    self.type.downcase
  end
end

#multiline?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/pdftk_forms/field.rb', line 15

def multiline?
  self.type == 'Text' && check_bit_true(4096, 13)
end

#push_button?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pdftk_forms/field.rb', line 19

def push_button?
  self.type == 'Button' && check_bit_true(65536, 17)
end

#radio_button?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pdftk_forms/field.rb', line 23

def radio_button?
  self.type == 'Button' && !push_button? && check_bit_true(32768, 16)
end

#required?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/pdftk_forms/field.rb', line 11

def required?
  check_bit_true(2, 2)
end