Class: Hexdump::Numeric::Decimal Private

Inherits:
FormatString show all
Defined in:
lib/hexdump/numeric/decimal.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

Constant Summary collapse

INT_SIZE_TO_WIDTH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

{
  1 => 3,  # 0xff.to_s(10).length
  2 => 5,  # 0xffff.to_s(10).length
  4 => 10, # 0xffffffff.to_s(10).length
  8 => 20  # 0xffffffffffffffff.to_s(10).length
}
FLOAT_SIZE_TO_WIDTH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

{
  4 => 15,
  8 => 24
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FormatString

#%, #to_s

Constructor Details

#initialize(type) ⇒ Decimal

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the decimal format.

Parameters:

Since:

  • 1.0.0



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hexdump/numeric/decimal.rb', line 32

def initialize(type)
  widths = case type
           when Type::Float then FLOAT_SIZE_TO_WIDTH
           else                  INT_SIZE_TO_WIDTH
           end

  @width = widths.fetch(type.size) do
    raise(NotImplementedError,"type #{type} with unsupported size #{type.size}")
  end

  case type
  when Type::Float
    super("% #{@width}g"); @width += 1
  else
    if type.signed?
      super("% #{@width}d"); @width += 1
    else
      super("%#{@width}d")
    end
  end
end

Instance Attribute Details

#widthInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)

Since:

  • 1.0.0



25
26
27
# File 'lib/hexdump/numeric/decimal.rb', line 25

def width
  @width
end