Sha256: c457104fc31675b446226ebfa4fed16491bba19ee162fdcfc4ebbce81642a8c5

Contents?: true

Size: 840 Bytes

Versions: 2

Compression:

Stored size: 840 Bytes

Contents

module Hexdump
  #
  # @api private
  #
  # @since 1.0.0
  #
  class Chars

    # The encoding to convert the characters to.
    #
    # @return [Encoding, nil]
    attr_reader :encoding

    #
    # Initializes the chars formatter.
    #
    # @param [Encoding, nil] encoding
    #   The encoding to convert characters to.
    #
    def initialize(encoding=nil)
      @encoding = encoding
    end

    #
    # Formats a string of characters.
    #
    # @param [String] chars
    #   The input string of raw characters.
    #
    # @return [String]
    #   The formatted string of raw characters.
    #
    def scrub(chars)
      if @encoding
        chars.force_encoding(@encoding)
        chars.scrub!('.')
        chars.gsub!(/[^[:print:]]/u,'.')
      else
        chars.tr!("^\x20-\x7e",'.')
      end

      chars
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hexdump-1.0.1 lib/hexdump/chars.rb
hexdump-1.0.0 lib/hexdump/chars.rb