Class: Vedeu::Compressor
- Inherits:
-
Object
- Object
- Vedeu::Compressor
- Defined in:
- lib/vedeu/output/compressor.rb
Overview
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.
Instance Attribute Summary collapse
- #output ⇒ Array<Array<Vedeu::Char>> readonly protected
Instance Method Summary collapse
- #colour_for(char) ⇒ String private
- #initialize(output) ⇒ Vedeu::Compressor constructor
- #render ⇒ String
- #style_for(char) ⇒ String private
Constructor Details
#initialize(output) ⇒ Vedeu::Compressor
10 11 12 13 14 |
# File 'lib/vedeu/output/compressor.rb', line 10 def initialize(output) @output = output @colour = '' @style = '' end |
Instance Attribute Details
#output ⇒ Array<Array<Vedeu::Char>> (readonly, protected)
39 40 41 |
# File 'lib/vedeu/output/compressor.rb', line 39 def output @output end |
Instance Method Details
#colour_for(char) ⇒ String (private)
45 46 47 48 49 50 |
# File 'lib/vedeu/output/compressor.rb', line 45 def colour_for(char) return '' if char.colour == @colour @colour = char.colour @colour.to_s end |
#render ⇒ String
Note:
Takes approximately ~70ms for 2100 chars. (2015-05-24)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vedeu/output/compressor.rb', line 18 def render Array(output).flatten.map do |char| if char.is_a?(Vedeu::Char) out = '' out << char.position.to_s out << colour_for(char) out << style_for(char) out << char.value out else char.to_s end end.join end |
#style_for(char) ⇒ String (private)
54 55 56 57 58 59 |
# File 'lib/vedeu/output/compressor.rb', line 54 def style_for(char) return '' if char.style == @style @style = char.style @style.to_s end |