Method: Cloudinary::Analytics#encode_version
- Defined in:
- lib/cloudinary/analytics.rb
#encode_version(version) ⇒ String
Encodes a semVer-like version string.
Example:
input: '1.24.0'
explode: ['1','24','0']
pad: ['01','24','00']
reverse: ['00', '24', '01']
implode: '002401'
int: 2401
binary: '100101100001'
padded: '000000100101100001'
str_split: ['000000', '100101', '100001']
getKey: ['A', 'l', 'h']
implode: 'Alh'
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cloudinary/analytics.rb', line 116 def encode_version(version) parts = version.split('.') padded_parts = parts.map { |part| part.rjust(2, '0') } number = padded_parts.reverse.join.to_i padded_binary = int_to_padded_bin(number, parts.length * BINARY_PAD_SIZE) raise RangeError, 'Version must be smaller than 43.21.26' if padded_binary.length % BINARY_PAD_SIZE != 0 encoded_chars = padded_binary.chars.each_slice(BINARY_PAD_SIZE).map { |slice| get_key(slice.join) } encoded_chars.join end |