class Pairtree::Identifier
Constants
- DECODE_REGEX
- ENCODE_REGEX
Public Class Methods
char2hex(c)
click to toggle source
Convert a character to its pairtree hexidecimal representation @param [Char] c The character to convert
# File lib/pairtree/identifier.rb, line 23 def self.char2hex c c.unpack('H*')[0].scan(/../).map { |x| "^#{x}"} end
decode(id)
click to toggle source
Decode special characters within an identifier @param [String] id The identifier
# File lib/pairtree/identifier.rb, line 16 def self.decode id id.tr('=+,', '/:.').gsub(DECODE_REGEX) { |h| hex2char(h) } end
encode(id)
click to toggle source
Encode special characters within an identifier @param [String] id The identifier
# File lib/pairtree/identifier.rb, line 9 def self.encode id id.gsub(ENCODE_REGEX) { |c| char2hex(c) }.tr('/:.', '=+,') end
hex2char(h)
click to toggle source
Convert a pairtree hexidecimal string to its character representation @param [String] h The hexidecimal string to convert
# File lib/pairtree/identifier.rb, line 30 def self.hex2char h '' << h.delete('^').hex end