Class: BinaryCodec::FieldLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/binary-codec/enums/fields.rb

Overview

TODO: See if this makes sense or if Ruby hashes are just fine

Instance Method Summary collapse

Constructor Details

#initialize(fields:, types:) ⇒ FieldLookup



66
67
68
69
70
71
72
73
74
75
# File 'lib/binary-codec/enums/fields.rb', line 66

def initialize(fields:, types:)
  @fields_hash = {}

  fields.each do |name, field_info|
    type_ordinal = types[field_info.type]
    field = build_field([name, field_info], type_ordinal) # Store the built field
    @fields_hash[name] = field                           # Map field by name
    @fields_hash[field.ordinal.to_s] = field             # Map field by ordinal
  end
end

Instance Method Details

#from_string(value) ⇒ Object

Method to retrieve a FieldInstance by its string key



78
79
80
# File 'lib/binary-codec/enums/fields.rb', line 78

def from_string(value)
  @fields_hash[value]
end