Class: BinStruct::Int16Enum

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

Overview

Enumeration on 2-byte integer. See Enum.

Author:

  • LemonTree55

Direct Known Subclasses

Int16beEnum, Int16leEnum

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 = {}) ⇒ Int16Enum

Returns a new instance of Int16Enum.

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)


112
113
114
115
116
117
118
# File 'lib/bin_struct/enum.rb', line 112

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