module Record::InstanceMethods

Instance Methods

Defines behavior for instances of a subclass of Flat::File regarding the creating of Records from a line of text from a flat file.

Public Instance Methods

create_record(line, line_number = -1) click to toggle source

create a record from line. The line is one line (or record) read from the text file. The resulting record is an object which. The object takes signals for each field according to the various fields defined with add_field or varients of it.

line_number is an optional line number of the line in a file of records. If line is not in a series of records (lines), omit and it’ll be -1 in the resulting record objects. Just make sure you realize this when reporting errors.

Both a getter (field_name), and setter (field_name=) are available to the user.

# File lib/flat/record.rb, line 45
def create_record line, line_number = -1
  attributes = {}
  values = line.unpack pack_format # Parse the incoming line
  fields.each_with_index do |field, index|
    attributes[field.name] = field.filter values[index]
  end
  Record::Definition.new self.class, attributes, line_number
end