Class: Hexdump::Numeric::Binary Private
- Inherits:
-
FormatString
- Object
- FormatString
- Hexdump::Numeric::Binary
- Defined in:
- lib/hexdump/numeric/binary.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
- 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 => 8, # 0xff.to_s(2).length 2 => 16, # 0xffff.to_s(2).length 4 => 32, # 0xffffffff.to_s(2).length 8 => 64 # 0xffffffffffffffff.to_s(2).length }
Instance Attribute Summary collapse
- #width ⇒ Integer readonly private
Instance Method Summary collapse
-
#initialize(type) ⇒ Binary
constructor
private
Initializes the binary format.
Methods inherited from FormatString
Constructor Details
#initialize(type) ⇒ Binary
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 binary format.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |
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.
21 22 23 |
# File 'lib/hexdump/numeric/binary.rb', line 21 def width @width end |