Module: FileData::ClassMethods

Defined in:
lib/flat/file_data.rb

Overview

Class Methods

Defines behavior for subclasses of Flat::File regarding the management of its internal data structures.

Instance Method Summary collapse

Instance Method Details

#fieldsObject

Convenience method for accessing flat_file_data[:fields]

Returns an Array of Field::Definitions



39
40
41
# File 'lib/flat/file_data.rb', line 39

def fields
  flat_file_data[:fields]
end

#flat_file_dataObject

Container for various points of data as defined in the Flat::File subclass.

Returns a Hash with the following keys:

  • :width - The overall width, or length, of a line in the flat file.

  • :pack_format - A format String for use by String#unpack.

  • :fields - An Array of Field::Definitions

  • :layouts - An Array of Layout::Definitions



25
26
27
28
29
30
31
32
# File 'lib/flat/file_data.rb', line 25

def flat_file_data
  @data ||= {
    :width       => 0,
    :pack_format => '',
    :fields      => [],
    :layouts     => [],
  }
end

#layoutsObject

Convenience method for accessing flat_file_data[:layouts]

Returns an Array of Layout::Definitions



74
75
76
# File 'lib/flat/file_data.rb', line 74

def layouts
  flat_file_data[:layout]
end

#pack_formatObject

Convenience method for accessing flat_file_data[:pack_format]

Returns a String sutiable for use with String#unpack



65
66
67
# File 'lib/flat/file_data.rb', line 65

def pack_format
  flat_file_data[:pack_format]
end

#reset_file_dataObject

Added for test purposes, primarily. DESTRUCTIVE!



81
82
83
# File 'lib/flat/file_data.rb', line 81

def reset_file_data #:nodoc:
  @data = nil
end

#widthObject

Convenience method for accessing flat_file_data[:width]

Returns the overall length of a line to text in the flat file.



48
49
50
# File 'lib/flat/file_data.rb', line 48

def width
  flat_file_data[:width]
end

#width=(value) ⇒ Object

Added setter to support +=, -= constructs; also allows direct assignment.



56
57
58
# File 'lib/flat/file_data.rb', line 56

def width=(value) #:nodoc:
  flat_file_data[:width] = value
end