Class: BookLab::Plantuml
- Inherits:
-
Object
- Object
- BookLab::Plantuml
- Defined in:
- lib/booklab/plantuml.rb
Class Method Summary collapse
Class Method Details
.append3bytes(b1, b2, b3) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/booklab/plantuml.rb', line 19 def append3bytes(b1, b2, b3) c1 = b1 >> 2 c2 = ((b1 & 0x3) << 4) | (b2 >> 4) c3 = ((b2 & 0xF) << 2) | (b3 >> 6) c4 = b3 & 0x3F return encode6bit(c1 & 0x3F).chr + encode6bit(c2 & 0x3F).chr + encode6bit(c3 & 0x3F).chr + encode6bit(c4 & 0x3F).chr end |
.encode(text) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/booklab/plantuml.rb', line 6 def encode(text) result = "" compressedData = Zlib::Deflate.deflate(text) compressedData.chars.each_slice(3) do |bytes| #print bytes[0], ' ' , bytes[1] , ' ' , bytes[2] b1 = bytes[0].nil? ? 0 : (bytes[0].ord & 0xFF) b2 = bytes[1].nil? ? 0 : (bytes[1].ord & 0xFF) b3 = bytes[2].nil? ? 0 : (bytes[2].ord & 0xFF) result += append3bytes(b1, b2, b3) end result end |
.encode6bit(b) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/booklab/plantuml.rb', line 30 def encode6bit(b) if b < 10 return ('0'.ord + b).chr end b = b - 10 if b < 26 return ('A'.ord + b).chr end b = b - 26 if b < 26 return ('a'.ord + b).chr end b = b - 26 if b == 0 return '-' end if b == 1 return '_' end return '?' end |