Class: F4R::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/f4r.rb

Overview

Stores records and meta data for encoding and decoding

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ Registry

Returns a new instance of Registry.



1242
1243
1244
1245
1246
# File 'lib/f4r.rb', line 1242

def initialize(header)
  @header = header
  @records = []
  @definitions = []
end

Instance Attribute Details

#definitionsArray<Hash>

Definitions for all records

Returns:

  • (Array<Hash>)


1240
1241
1242
# File 'lib/f4r.rb', line 1240

def definitions
  @definitions
end

#headerBinData::RecordHeader (readonly)

Main file header

Returns:

  • (BinData::RecordHeader)

    header



1226
1227
1228
# File 'lib/f4r.rb', line 1226

def header
  @header
end

#recordsHash

Storage for all records including their meta data

Returns:

  • (Hash)


1233
1234
1235
# File 'lib/f4r.rb', line 1233

def records
  @records
end

Instance Method Details

#add(record, local_message_number) ⇒ Object

Add record to @records [Array<Hash>]

Parameters:

  • record (Hash)
  • local_message_number (Integer)


1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/f4r.rb', line 1254

def add(record, local_message_number)
  @records << {
    index: @records.size,
    message_name: record.message[:name],
    message_number: record.message[:number],
    message_source: record.message[:source],
    local_message_number: local_message_number,
    fields: record.fields
  }
end

#definition(record) ⇒ Hash

Helper method to find the associated definitions with an specific record

Parameters:

  • record (Hash)

Returns:

  • (Hash)


1271
1272
1273
1274
1275
1276
# File 'lib/f4r.rb', line 1271

def definition(record)
  definitions.find do |d|
    d[:local_message_number] == record[:local_message_number] &&
      d[:message_name] == record[:message_name]
  end
end