Class: Unidom::Common::Numeration

Inherits:
Object
  • Object
show all
Defined in:
lib/unidom/common/numeration.rb

Overview

Numeration 是数字格式转换的辅助类。

Class Method Summary collapse

Class Method Details

.hex(data) ⇒ Object

将二进制数据转换成 16 进制的表达。如: Unidom::Common::Numeration.hex [ ‘A’, ‘}’ ]



11
12
13
# File 'lib/unidom/common/numeration.rb', line 11

def self.hex(data)
  data.present? ? data.unpack('H*')[0] : nil
end

.rev_hex(hex) ⇒ Object

将十六进制数的表达字符串,转换成二进制数据。如: Unidom::Common::Numeration.rev_hex ‘6CA0’



18
19
20
# File 'lib/unidom/common/numeration.rb', line 18

def self.rev_hex(hex)
  hex.present? ? hex.scan(/../).map(&:hex).pack('c*') : nil
end