Class: Arrolio::Content::FormField

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/content/form_field.rb

Overview

A form field for interactive PDF AcroForm. Carries the field type, name, value, and geometry. The renderer emits it as a PDAcroForm widget (text field, checkbox, radio button) during post-processing. This model captures the semantic intent; the actual PDF widget creation is a renderer post-pass.

Constant Summary collapse

TYPES =
%i[text checkbox radio signature].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, name:, page_number:, x:, y:, width:, height:, value: nil, style_id: :form_field) ⇒ FormField

Returns a new instance of FormField.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/arrolio/content/form_field.rb', line 16

def initialize(type:, name:, page_number:, x:, y:, width:, height:, value: nil, style_id: :form_field)
  @type = type.to_sym
  @name = name.to_s
  @value = value
  @page_number = page_number.to_i
  @x = x.to_f
  @y = y.to_f
  @width = width.to_f
  @height = height.to_f
  @style_id = style_id.to_sym
  freeze
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def height
  @height
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def name
  @name
end

#page_numberObject (readonly)

Returns the value of attribute page_number.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def page_number
  @page_number
end

#style_idObject (readonly)

Returns the value of attribute style_id.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def style_id
  @style_id
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def value
  @value
end

#widthObject (readonly)

Returns the value of attribute width.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



13
14
15
# File 'lib/arrolio/content/form_field.rb', line 13

def y
  @y
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



33
34
35
36
37
38
39
# File 'lib/arrolio/content/form_field.rb', line 33

def ==(other)
  other.is_a?(self.class) &&
    type == other.type && name == other.name &&
    value == other.value && page_number == other.page_number &&
    x == other.x && y == other.y &&
    width == other.width && height == other.height
end

#checkbox?Boolean

Returns:

  • (Boolean)


30
# File 'lib/arrolio/content/form_field.rb', line 30

def checkbox? = @type == :checkbox

#hashObject



42
43
44
# File 'lib/arrolio/content/form_field.rb', line 42

def hash
  [self.class, type, name, value, page_number, x, y, width, height].hash
end

#radio?Boolean

Returns:

  • (Boolean)


31
# File 'lib/arrolio/content/form_field.rb', line 31

def radio? = @type == :radio

#text?Boolean

Returns:

  • (Boolean)


29
# File 'lib/arrolio/content/form_field.rb', line 29

def text? = @type == :text