Class: Vedeu::Output::Compressor Private
- Inherits:
-
Object
- Object
- Vedeu::Output::Compressor
- Includes:
- Common, Renderers::Options
- 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::Cells::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::Cells::Char>> readonly protected private
Attributes included from Renderers::Options
Class Method Summary collapse
Instance Method Summary collapse
-
#content ⇒ Array
private
private
Returns the output with all of the empty cells removed to make compression faster.
- #content_size ⇒ Fixnum private private
-
#initialize(output, options = {}) ⇒ Vedeu::Output::Compressor
constructor
private
Returns a new instance of Vedeu::Output::Compressor.
- #original_size ⇒ Fixnum private private
- #output? ⇒ Boolean private private
- #render ⇒ String, Array<void>|String private
Methods included from Renderers::Options
#clear, #compression, #compression?, #default_template, #defaults, #end_row_tag, #end_tag, #filename, #start_row_tag, #start_tag, #template, #timestamp, #timestamp?, #write, #write_file, #write_file?
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
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.
31 32 33 34 |
# File 'lib/vedeu/output/compressor.rb', line 31 def initialize(output, = {}) @output = output @options = end |
Instance Attribute Details
#output ⇒ Array<Array<Vedeu::Cells::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.
55 56 57 |
# File 'lib/vedeu/output/compressor.rb', line 55 def output @output end |
Class Method Details
.render(output, options = {}) ⇒ String, Array<void>|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.
21 22 23 |
# File 'lib/vedeu/output/compressor.rb', line 21 def self.render(output, = {}) new(output, ).render end |
Instance Method Details
#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.
Returns the output with all of the empty cells removed to make compression faster.
63 64 65 66 67 68 69 |
# File 'lib/vedeu/output/compressor.rb', line 63 def content @_content ||= Vedeu.timer('Removing empty cells...') do output.content.reject do |cell| cell.class == Vedeu::Cells::Empty end end end |
#content_size ⇒ Fixnum (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.
72 73 74 |
# File 'lib/vedeu/output/compressor.rb', line 72 def content_size content.size end |
#original_size ⇒ Fixnum (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.
77 78 79 |
# File 'lib/vedeu/output/compressor.rb', line 77 def original_size output.content.size end |
#output? ⇒ Boolean (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 |
# File 'lib/vedeu/output/compressor.rb', line 82 def output? present?(output) end |
#render ⇒ String, Array<void>|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 ~6ms for 2100 chars. (2015-11-25)
-
Takes approximately ~25ms for 2100 chars. (2015-07-25)
41 42 43 44 45 46 47 48 49 |
# File 'lib/vedeu/output/compressor.rb', line 41 def render return [] unless output? Vedeu.log(type: :compress, message: "Original size: #{original_size} / " \ "New size: #{content_size}") Vedeu::Output::CompressorCache.cache(content, compression?) end |