Class: BinStruct::Int32Enum

Inherits:
Enum
  • Object
show all
Defined in:
lib/bin_struct/enum.rb

Overview

Enumeration on 4-byte integer. See Enum.

Author:

  • LemonTree55

Direct Known Subclasses

Int32beEnum, Int32leEnum

Instance Attribute Summary

Attributes inherited from Enum

#enum

Attributes inherited from Int

#default, #endian, #value, #width

Instance Method Summary collapse

Methods inherited from Enum

#format_inspect, #to_human, #value=

Methods inherited from Int

#format_inspect, #from_human, #nbits, #read, #sz, #to_f, #to_i, #to_s

Methods included from Structable

#format_inspect, #read, #sz, #to_human, #to_s, #type_name

Constructor Details

#initialize(options = {}) ⇒ Int32Enum

Returns a new instance of Int32Enum.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :enum (Hash{::String => Integer})

    enumerated values. Default value is taken from first element unless given. This option is mandatory.

  • :endian (:big, :little)
  • :value (Integer, ::String)
  • :default (Integer, ::String)


166
167
168
169
170
171
172
# File 'lib/bin_struct/enum.rb', line 166

def initialize(options = {})
  opts = options.slice(:enum, :endian, :default, :value)
  opts[:endian] ||= :big
  opts[:width] = 4
  super(opts)
  @packstr = { big: 'N', little: 'V' }
end