Class: F4R::Record

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

Overview

Record is where each data message gets stored including meta data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_name) ⇒ Record

Returns a new instance of Record.



1311
1312
1313
1314
# File 'lib/f4r.rb', line 1311

def initialize(message_name)
  @message_name = message_name
  @fields = {}
end

Instance Attribute Details

#fieldsHash (readonly)

Where all fields for the specific record get stored

Examples:

{
  field_1: {
    value: value,
    base_type: base_type,
    message_name: 'file_id',
    message_number: 0,
    properties: {...}, # copy of global message's field
  },
  field_2: {
    value: value,
    base_type: base_type,
    message_name: 'file_id',
    message_number: 0,
    properties: {...}, # copy of global message's field
  },
 ...
}

Returns:

  • (Hash)

    current message fields.



1309
1310
1311
# File 'lib/f4r.rb', line 1309

def fields
  @fields
end

Instance Method Details

#messageHash

Global message

Returns:

  • (Hash)

    copy of associated global message.



1321
1322
1323
# File 'lib/f4r.rb', line 1321

def message
  @message ||= GlobalFit.messages.find { |m| m[:name] == @message_name }
end

#set_field_value(definition, value) ⇒ Object

Sets the value attribute for the passed field.

Parameters:

  • definition (RecordField)
  • value (String, Integer)


1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
# File 'lib/f4r.rb', line 1331

def set_field_value(definition, value)
  if fields[definition.name]
    @fields[definition.name][:value] = value
    @fields[definition.name][:definition] = definition
  else
    @fields[definition.name] = {
      value: value,
      base_type: definition.base_type_definition,
      message_name: definition.global_message[:name],
      message_number: definition.global_message[:number],
      definition: definition,
      properties: definition.global_message_field,
    }
  end
end