Module: JekyllRemotePlantUMLPlugin::Utils::Encode
- Included in:
- Block
- Defined in:
- lib/jekyll_remote_plantuml_plugin/utils.rb
Instance Method Summary collapse
-
#append3bytes(bit1, bit2, bit3) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #encode(content) ⇒ Object
- #encode64(content) ⇒ Object
-
#encode6bit(b) ⇒ Object
rubocop:disable Naming/MethodParameterName.
Instance Method Details
#append3bytes(bit1, bit2, bit3) ⇒ Object
rubocop:disable Metrics/AbcSize
43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
rubocop:disable Naming/MethodParameterName
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |