Class: Moneta::Transforms::Hex

Inherits:
Moneta::Transform show all
Defined in:
lib/moneta/transforms/hex.rb

Overview

Encodes the string as a string representation of the bytes in hexadecimal

Examples:

Moneta::Transforms::Hex.new.encode("Hello") # => "48656c6c6f"

Instance Method Summary collapse

Methods inherited from Moneta::Transform

#decodable?, delegate_to, #initialize, #method_missing, #respond_to_missing?

Constructor Details

This class inherits a constructor from Moneta::Transform

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Moneta::Transform

Instance Method Details

#decode(value) ⇒ String

Decodes from hexadecimal

Parameters:

  • value (String)

Returns:

  • (String)


20
21
22
# File 'lib/moneta/transforms/hex.rb', line 20

def decode(value)
  [value].pack("H*")
end

#encode(value) ⇒ String

Encodes to hexadecimal

Parameters:

  • value (String)

Returns:

  • (String)


12
13
14
# File 'lib/moneta/transforms/hex.rb', line 12

def encode(value)
  value.unpack1("H*")
end