Sha256: b2b9bc31e2794ee0b720a6199284a222bff7b2a4eb52d679c599823000147f66
Contents?: true
Size: 1.83 KB
Versions: 4
Compression:
Stored size: 1.83 KB
Contents
module Vedeu # During the conversion of a Vedeu::Char object into a string of escape # sequences, this class removes multiple occurences of the same escape # sequence, resulting in a smaller payload being sent to the renderer. # # @api private class Compressor # @param output [Array<Array<Vedeu::Char>>] # @return [String] def self.render(output) new(output).render end # Returns a new instance of Vedeu::Compressor. # # @param output [Array<Array<Vedeu::Char>>] # @return [Vedeu::Compressor] def initialize(output) @output = output @colour = '' @style = '' end # @note Takes approximately ~70ms for 2100 chars. (2015-05-24) # @return [String] def render if Vedeu::Configuration.compression? compress else uncompress end end protected # @!attribute [r] output # @return [Array<Array<Vedeu::Char>>] attr_reader :output private # @return [String] def compress out = '' Array(output).flatten.each do |char| out << char.position.to_s out << colour_for(char) out << style_for(char) out << char.value end out end # @return [String] def uncompress out = '' Array(output).flatten.each do |char| out << char.position.to_s out << char.colour.to_s out << char.style.to_s out << char.value end out end # @param char [Vedeu::Char] # @return [String] def colour_for(char) return '' if char.colour == @colour @colour = char.colour @colour.to_s end # @param char [Vedeu::Char] # @return [String] def style_for(char) return '' if char.style == @style @style = char.style @style.to_s end end # Compressor end # Vedeu
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.4.56 | lib/vedeu/output/compressor.rb |
vedeu-0.4.55 | lib/vedeu/output/compressor.rb |
vedeu-0.4.54 | lib/vedeu/output/compressor.rb |
vedeu-0.4.53 | lib/vedeu/output/compressor.rb |