Class: Scl::Hex

Inherits:
Format show all
Defined in:
lib/scl/formats/hex.rb

Constant Summary

Constants inherited from Format

Format::AUTO, Format::BASE64, Format::BINARY, Format::HEX, Format::QRCODE, Format::STDOUT, Format::WORDS

Instance Method Summary collapse

Methods inherited from Format

#name, #output, #read

Instance Method Details

#decode(data) ⇒ Object



7
8
9
# File 'lib/scl/formats/hex.rb', line 7

def decode(data)
  data.scan(/../).map{|s| s.to_i(16) }.map(&:chr).join
end

#encode(data) ⇒ Object



3
4
5
# File 'lib/scl/formats/hex.rb', line 3

def encode(data)
  data.bytes.map{|x| x.to_s(16).rjust(2, ?0) }.join
end