module JekyllRemotePlantUMLPlugin::Utils::Encode
Public Instance Methods
append3bytes(bit1, bit2, bit3)
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/jekyll_remote_plantuml_plugin/utils.rb, line 43 def append3bytes(bit1, bit2, bit3) c1 = bit1 >> 2 c2 = ((bit1 & 0x3) << 4) | (bit2 >> 4) c3 = ((bit2 & 0xF) << 2) | (bit3 >> 6) c4 = bit3 & 0x3F encode6bit(c1 & 0x3F).chr + encode6bit(c2 & 0x3F).chr + encode6bit(c3 & 0x3F).chr + encode6bit(c4 & 0x3F).chr end
encode(content)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/utils.rb, line 21 def encode(content) encoded = content.force_encoding("utf-8") encoded = Zlib::Deflate.new(nil, -Zlib::MAX_WBITS).deflate(encoded, Zlib::FINISH) encode64(encoded) end
encode64(content)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/utils.rb, line 27 def encode64(content) length = content.length ind = 0 out = "" while ind < length i1 = ind + 1 < length ? content[ind + 1].ord : 0 i2 = ind + 2 < length ? content[ind + 2].ord : 0 out += append3bytes(content[ind].ord, i1, i2) ind += 3 end out end
encode6bit(b)
click to toggle source
rubocop:disable Naming/MethodParameterName
# File lib/jekyll_remote_plantuml_plugin/utils.rb, line 56 def encode6bit(b) return (48 + b).chr if b < 10 b -= 10 return (65 + b).chr if b < 26 b -= 26 return (97 + b).chr if b < 26 b -= 26 return "-" if b.zero? b == 1 ? "_" : "?" end