Class: Hexdump::Numeric::CharOrInt Private
- Inherits:
-
FormatString
- Object
- FormatString
- Hexdump::Numeric::CharOrInt
- Defined in:
- lib/hexdump/numeric/char_or_int.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.
Instance Attribute Summary collapse
- #base ⇒ Hexadecimal, ... readonly private
- #encoding ⇒ Encoding? readonly private
Instance Method Summary collapse
-
#%(value) ⇒ String
private
Formats a given ASCII byte value to a character or numeric format.
-
#initialize(base, encoding = nil) ⇒ CharOrInt
constructor
private
Initializes the character format.
-
#width ⇒ Integer
private
The string width associated with the numeric base.
Methods inherited from FormatString
Constructor Details
#initialize(base, encoding = nil) ⇒ CharOrInt
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 character format.
28 29 30 31 32 33 |
# File 'lib/hexdump/numeric/char_or_int.rb', line 28 def initialize(base,encoding=nil) @base = base @encoding = encoding super("%#{@base.width}s") end |
Instance Attribute Details
#base ⇒ Hexadecimal, ... (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.
13 14 15 |
# File 'lib/hexdump/numeric/char_or_int.rb', line 13 def base @base end |
#encoding ⇒ Encoding? (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.
16 17 18 |
# File 'lib/hexdump/numeric/char_or_int.rb', line 16 def encoding @encoding end |
Instance Method Details
#%(value) ⇒ String
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.
Formats a given ASCII byte value to a character or numeric format.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hexdump/numeric/char_or_int.rb', line 53 def %(value) if value == 0x00 super("\\0") elsif value == 0x07 super("\\a") elsif value == 0x08 super("\\b") elsif value == 0x09 super("\\t") elsif value == 0x0a super("\\n") elsif value == 0x0b super("\\v") elsif value == 0x0c super("\\f") elsif value == 0x0d super("\\r") else if @encoding if value >= 0x00 char = value.chr(@encoding) rescue nil if char && char =~ /[[:print:]]/ super(char) else @base % value end else @base % value end else if (value >= 0x20 && value <= 0x7e) super(value.chr) else @base % value end end end end |
#width ⇒ Integer
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.
The string width associated with the numeric base.
40 41 42 |
# File 'lib/hexdump/numeric/char_or_int.rb', line 40 def width @base.width end |