class PdfTempura::Document::BoxedCharacters

Attributes

box_spacing[R]
box_width[R]
coordinates[RW]
groups[R]
padding[R]
text_options[R]
truncate[R]
truncate?[R]

Public Class Methods

new(name, coordinates, height, options = {}, &block) click to toggle source
Calls superclass method PdfTempura::Document::Field::Base::new
# File lib/pdf_tempura/document/boxed_characters.rb, line 12
def initialize(name, coordinates, height, options = {}, &block)
  @groups = []

  super name, coordinates, [0, height], options

  instance_eval(&block) if block_given?
end

Public Instance Methods

characters(characters) click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 20
def characters(characters)
  @groups << CharacterGroup.new(characters)
end
dimensions() click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 40
def dimensions
  [width, @dimensions[1]]
end
fields() click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 32
def fields
  @fields ||= generate_text_fields
end
space(width) click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 24
def space(width)
  @groups << SpaceGroup.new(width)
end
supported_characters() click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 28
def supported_characters
  @groups.map(&:characters).inject(:+)
end
width() click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 36
def width
  groups.inject(0){ |sum,group| sum + group.width(box_width, box_spacing) }
end

Private Instance Methods

generate_text_fields() click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 46
def generate_text_fields
  [].tap do |fields|
    groups.inject(self.x) do |x, group|
      group.each_supported_character do
        fields << Document::CharacterField.new(name, [x,y], [box_width,height], text_options)
        x+= box_width + box_spacing
      end

      x + group.spacing - (group.characters > 0 ? box_spacing : 0)
    end
  end
end
load_options(options) click to toggle source
# File lib/pdf_tempura/document/boxed_characters.rb, line 59
def load_options(options)
  @box_width = options["box_width"]
  @box_spacing = options["box_spacing"]
  @truncate = options["truncate"] || false
  @text_options = options.reject { |key,v| ["box_width", "box_spacing", "truncate"].include?(key) }
  @padding = [0,0,0,0]
end