Class: Vedeu::Output::Compressor Private

Inherits:
Object
  • Object
show all
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

Attributes included from Renderers::Options

#options

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

Options Hash (options):



31
32
33
34
# File 'lib/vedeu/output/compressor.rb', line 31

def initialize(output, options = {})
  @output  = output
  @options = options
end

Instance Attribute Details

#outputArray<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.

Returns:



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.

Parameters:

Returns:

  • (String)
  • (Array<void>|String)


21
22
23
# File 'lib/vedeu/output/compressor.rb', line 21

def self.render(output, options = {})
  new(output, options).render
end

Instance Method Details

#contentArray (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.

Returns:

  • (Array)


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_sizeFixnum (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:

  • (Fixnum)


72
73
74
# File 'lib/vedeu/output/compressor.rb', line 72

def content_size
  content.size
end

#original_sizeFixnum (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:

  • (Fixnum)


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.

Returns:



82
83
84
# File 'lib/vedeu/output/compressor.rb', line 82

def output?
  present?(output)
end

#renderString, 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.

Note:
  • Takes approximately ~6ms for 2100 chars. (2015-11-25)

  • Takes approximately ~25ms for 2100 chars. (2015-07-25)

Returns:

  • (String)
  • (Array<void>|String)


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