Parent

Methods

Included Modules

Class/Module Index [+]

Quicksearch

Origami::Filter::ASCIIHex

Class representing a filter used to encode and decode data written into hexadecimal.

Public Instance Methods

decode(string) click to toggle source

Decodes given data writen into upcase hexadecimal representation.

string

The data to decode.

# File lib/origami/filters/ascii.rb, line 53
def decode(string)
  
  input = string.include?(>>) ? string[0..string.index(>>) - 1] : string
  digits = input.delete(" \f\t\r\n\00"").split(/(..)/).delete_if{|digit| digit.empty?}
  
  if not digits.all? { |d| d =~ /[a-fA-F0-9]{1,2}/ }
    raise InvalidASCIIHexStringError, input
  end
  
  digits.pack("H2" * digits.size)
end
encode(stream) click to toggle source

Encodes given data into upcase hexadecimal representation.

stream

The data to encode.

# File lib/origami/filters/ascii.rb, line 45
def encode(stream)
  stream.unpack("H2" * stream.size).join.upcase
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.