Module: Record::InstanceMethods
- Defined in:
- lib/flat/record.rb
Overview
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.
Instance Method Summary collapse
-
#create_record(line, line_number = -1) ⇒ Object
create a record from line.
Instance Method Details
#create_record(line, line_number = -1) ⇒ Object
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.
– NOTE: No line length checking here; consider making protected ++
45 46 47 48 49 50 51 52 |
# 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 |