module Field::ClassMethods
Class Methods¶ ↑
Defines behavior for subclasses of Flat::File
regarding the specification of the line structure contained in a flat file.
Public Instance Methods
add_field(name = nil, options = {}) { |field_def| ... }
click to toggle source
Add a field to the Flat::File
subclass. Options can include
:width - number of characters in field (default 10) :filter - callack, lambda or code block for processing during reading :formatter - callback, lambda, or code block for processing during writing
class SomeFile < Flat::File add_field :some_field_name, :width => 35 end
Options¶ ↑
# File lib/flat/field.rb, line 34 def add_field name = nil, options = {}, &block fields << field_def = Field::Definition.new(name, options, self) yield field_def if block_given? pack_format << field_def.pack_format self.width += field_def.width # TODO: Add a check here to ensure the Field has a name specified; it can be a String or Symbol return field_def end
pad(name, options = {})
click to toggle source
Add a pad field. To have the name auto generated, use :autoname for the name parameter. For options see add_field
.
# File lib/flat/field.rb, line 50 def pad name, options = {} add_field ( name == :autoname ? new_pad_name : name ), options.merge( padding: true ) end