Class: Hexdump::Chars Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hexdump/chars.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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoding = nil) ⇒ Chars

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 chars formatter.

Parameters:

  • encoding (Encoding, nil) (defaults to: nil)

    The encoding to convert characters to.

Since:

  • 1.0.0



20
21
22
# File 'lib/hexdump/chars.rb', line 20

def initialize(encoding=nil)
  @encoding = encoding
end

Instance Attribute Details

#encodingEncoding? (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.

The encoding to convert the characters to.

Returns:

  • (Encoding, nil)

Since:

  • 1.0.0



12
13
14
# File 'lib/hexdump/chars.rb', line 12

def encoding
  @encoding
end

Instance Method Details

#scrub(chars) ⇒ 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 string of characters.

Parameters:

  • chars (String)

    The input string of raw characters.

Returns:

  • (String)

    The formatted string of raw characters.

Since:

  • 1.0.0



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hexdump/chars.rb', line 33

def scrub(chars)
  if @encoding
    chars.force_encoding(@encoding)
    chars.scrub!('.')
    chars.gsub!(/[^[:print:]]/u,'.')
  else
    chars.tr!("^\x20-\x7e",'.')
  end

  chars
end