Class: Vedeu::Output::Compressor
- Inherits:
-
Object
- Object
- Vedeu::Output::Compressor
- Includes:
- Common
- Defined in:
- lib/vedeu/output/compressor.rb
Overview
During the conversion of a Vedeu::Views::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::Views::Char>> readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
- #colour_for(char) ⇒ String private
- #compress ⇒ String private
- #content ⇒ Array private
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#initialize(output, options = {}) ⇒ Vedeu::Output::Compressor
constructor
Returns a new instance of Vedeu::Output::Compressor.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
- #render ⇒ String
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
- #style_for(char) ⇒ String private
- #uncompress ⇒ String private
Constructor Details
#initialize(output, options = {}) ⇒ Vedeu::Output::Compressor
Returns a new instance of Vedeu::Output::Compressor.
26 27 28 29 30 31 |
# File 'lib/vedeu/output/compressor.rb', line 26 def initialize(output, = {}) @output = output = @colour = '' @style = '' end |
Instance Attribute Details
#output ⇒ Array<Array<Vedeu::Views::Char>> (readonly, protected)
46 47 48 |
# File 'lib/vedeu/output/compressor.rb', line 46 def output @output end |
Class Method Details
.render(output, options = {}) ⇒ String
16 17 18 |
# File 'lib/vedeu/output/compressor.rb', line 16 def self.render(output, = {}) new(output, ).render end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable is nil or empty.
#colour_for(char) ⇒ String (private)
86 87 88 89 90 91 |
# File 'lib/vedeu/output/compressor.rb', line 86 def colour_for(char) return ''.freeze if char.colour == @colour @colour = char.colour @colour.to_s end |
#compress ⇒ String (private)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vedeu/output/compressor.rb', line 58 def compress Vedeu.timer('Compression'.freeze) do out = '' content.each do |cell| out << cell.position.to_s out << colour_for(cell) out << style_for(cell) out << cell.value end out end end |
#content ⇒ Array (private)
51 52 53 54 55 |
# File 'lib/vedeu/output/compressor.rb', line 51 def content return [] if absent?(output) @content ||= output.content.reject(&:cell?) end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#render ⇒ String
Takes approximately ~25ms for 2100 chars. (2015-07-25)
36 37 38 39 40 |
# File 'lib/vedeu/output/compressor.rb', line 36 def render return compress if Vedeu::Configuration.compression? uncompress end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#style_for(char) ⇒ String (private)
95 96 97 98 99 100 |
# File 'lib/vedeu/output/compressor.rb', line 95 def style_for(char) return ''.freeze if char.style == @style @style = char.style @style.to_s end |
#uncompress ⇒ String (private)
74 75 76 77 78 79 80 81 82 |
# File 'lib/vedeu/output/compressor.rb', line 74 def uncompress out = '' content.each do |cell| out << cell.to_s end out end |