class Hexdump::Numeric::Binary

@api private

@since 1.0.0

Constants

SIZE_TO_WIDTH

Attributes

width[R]

@return [Integer]

Public Class Methods

new(type) click to toggle source

Initializes the binary format.

@param [Type::Int, Type::UInt] type

@raise [NotImplementedError]

@raise [IncompatibleTypeError]

@raise [TypeError]

Calls superclass method Hexdump::FormatString::new
# File lib/hexdump/numeric/binary.rb, line 34
def initialize(type)
  case type
  when Type::Int, Type::UInt
    @width = SIZE_TO_WIDTH.fetch(type.size) do
      raise(NotImplementedError,"type #{type} with unsupported size #{type.size}")
    end

    if type.signed?
      super("% .#{@width}b"); @width += 1
    else
      super("%.#{@width}b")
    end
  when Type::Float
    raise(IncompatibleTypeError,"cannot format floating-point numbers in binary")
  else
    raise(TypeError,"unsupported type: #{type.inspect}")
  end
end