Class: Vedeu::Output::Compressor Private
- Inherits:
-
Object
- Object
- Vedeu::Output::Compressor
- Includes:
- Common
- Defined in:
- lib/vedeu/output/compressor.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 private
Class Method Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#colour_for(char) ⇒ String
private
private
Compress by not repeatedly sending the same colours for each character which has the same colours as the last character output.
- #compress ⇒ String private private
- #content ⇒ Array private private
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#initialize(output, options = {}) ⇒ Vedeu::Output::Compressor
constructor
private
Returns a new instance of Vedeu::Output::Compressor.
-
#position_for(char) ⇒ String
private
private
Compress by not repeatedly sending a position when only the x coordinate has changed; i.e.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- #render ⇒ String private
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#style_for(char) ⇒ String
private
private
Compress by not repeatedly sending the same style(s) for each character which has the same style(s) as the last character output.
- #uncompress ⇒ String private private
Constructor Details
#initialize(output, options = {}) ⇒ Vedeu::Output::Compressor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Output::Compressor.
28 29 30 31 32 33 |
# File 'lib/vedeu/output/compressor.rb', line 28 def initialize(output, = {}) @output = output @options = @colour = '' @style = '' end |
Instance Attribute Details
#output ⇒ Array<Array<Vedeu::Views::Char>> (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/vedeu/output/compressor.rb', line 48 def output @output end |
Class Method Details
.render(output, options = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/vedeu/output/compressor.rb', line 18 def self.render(output, = {}) new(output, ).render end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#colour_for(char) ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compress by not repeatedly sending the same colours for each character which has the same colours as the last character output.
115 116 117 118 119 120 |
# File 'lib/vedeu/output/compressor.rb', line 115 def colour_for(char) return ''.freeze if char.colour == @colour @colour = char.colour @colour.to_s end |
#compress ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vedeu/output/compressor.rb', line 60 def compress Vedeu.timer("Compression for #{content.size} objects".freeze) do out = '' content.each do |cell| # out << position_for(cell) out << cell.position.to_s out << colour_for(cell) out << style_for(cell) out << cell.value end Vedeu.log(type: :output, message: "Compression: #{content.size} objects -> " \ "#{out.size} characters".freeze) out end end |
#content ⇒ Array (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 |
# File 'lib/vedeu/output/compressor.rb', line 53 def content return [] if absent?(output) @content ||= output.content.reject(&:cell?) end |
#demodulize(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the module part from the expression in the string.
#position_for(char) ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compress by not repeatedly sending a position when only the x coordinate has changed; i.e. we are on the same line, just advancing a character.
102 103 104 105 106 107 |
# File 'lib/vedeu/output/compressor.rb', line 102 def position_for(char) return ''.freeze if char.position.y == @y @y = char.position.y char.position.to_s end |
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#render ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Takes approximately ~25ms for 2100 chars. (2015-07-25)
38 39 40 41 42 |
# File 'lib/vedeu/output/compressor.rb', line 38 def render return compress if Vedeu::Configuration.compression? uncompress end |
#snake_case(name) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#style_for(char) ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compress by not repeatedly sending the same style(s) for each character which has the same style(s) as the last character output.
128 129 130 131 132 133 |
# File 'lib/vedeu/output/compressor.rb', line 128 def style_for(char) return ''.freeze if char.style == @style @style = char.style @style.to_s end |
#uncompress ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/output/compressor.rb', line 82 def uncompress out = '' content.each do |cell| out << cell.to_s end Vedeu.log(type: :output, message: "No compression: #{content.size} objects -> " \ "#{out.size} characters".freeze) out end |