Class Origami::Filter::ASCIIHex
In: sources/parser/filters.rb
Parent: Object

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

Methods

decode   encode  

Included Modules

Filter

Public Instance methods

Decodes given data writen into upcase hexadecimal representation.

string:The data to decode.

[Source]

     # File sources/parser/filters.rb, line 270
270:       def decode(string)
271:         
272:         input = string.include?(?>) ? string[0..string.index(?>) - 1] : string
273:         
274:         digits = input.delete(" \f\t\r\n\0").split(//)
275:         
276:         if not digits.all? { |d| d =~ /[a-fA-F0-9>]/ }
277:           raise InvalidASCIIHexString, input
278:         end
279:         
280:         digits << "0" unless digits.size % 2 == 0
281:         
282:         bytes = []
283:         for i in 0..digits.size/2-1 do bytes << digits[2*i].to_s + digits[2*i+1].to_s end
284:         
285:         bytes.pack("H2" * (digits.size / 2))
286:       end

Encodes given data into upcase hexadecimal representation.

stream:The data to encode.

[Source]

     # File sources/parser/filters.rb, line 262
262:       def encode(stream)
263:         stream.unpack("H2" * stream.size).join.upcase
264:       end

[Validate]