Class: Hexdump::Numeric::Decimal Private
- Inherits:
-
FormatString
- Object
- FormatString
- Hexdump::Numeric::Decimal
- 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.
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.
{ 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.
{ 4 => 15, 8 => 24 }
Instance Attribute Summary collapse
- #width ⇒ Integer readonly private
Instance Method Summary collapse
-
#initialize(type) ⇒ Decimal
constructor
private
Initializes the decimal format.
Methods inherited from FormatString
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.
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
#width ⇒ Integer (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.
25 26 27 |
# File 'lib/hexdump/numeric/decimal.rb', line 25 def width @width end |