Module: Vedeu::Output::CompressorCache Private

Extended by:
CompressorCache, Repositories::Storage
Included in:
CompressorCache
Defined in:
lib/vedeu/output/compressor_cache.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Store a copy of the data last processed by Compressor. Both the original content and the compressed versions are kept (unless modified) to speed up the rendering of the display.

Instance Method Summary collapse

Methods included from Repositories::Storage

reset!, storage

Instance Method Details

#cache(content, compression = false) ⇒ 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:

  • content (Array<void>)
  • compression (Boolean) (defaults to: false)

Returns:

  • (String)


22
23
24
25
26
# File 'lib/vedeu/output/compressor_cache.rb', line 22

def cache(content, compression = false)
  write(content, compression) unless empty?(content) || cached?(content)

  compression ? read(:compress) : read(:uncompress)
end

#cached?(content) ⇒ 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.

Parameters:

  • content (Array<void>)

Returns:



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

def cached?(content)
  size?(content) && same?(content)
end

#compress(content) ⇒ 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.

Parameters:

  • content (Array<void>)

Returns:

  • (String)


50
51
52
# File 'lib/vedeu/output/compressor_cache.rb', line 50

def compress(content)
  Vedeu::Output::Compressors::Character.with(content)
end

#empty?(content) ⇒ 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.

Parameters:

  • content (Array<void>)

Returns:



56
57
58
# File 'lib/vedeu/output/compressor_cache.rb', line 56

def empty?(content)
  content.nil? || content.empty?
end

#in_memoryHash<Symbol => Array<void>, 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.

Returns:

  • (Hash<Symbol => Array<void>, String>)


61
62
63
64
65
66
67
# File 'lib/vedeu/output/compressor_cache.rb', line 61

def in_memory
  {
    compress:   '',
    original:   [],
    uncompress: '',
  }
end

#read(key) ⇒ Array<void> (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.

Parameters:

  • key (NilClass|Symbol)

Returns:

  • (Array<void>)


71
72
73
# File 'lib/vedeu/output/compressor_cache.rb', line 71

def read(key)
  storage.fetch(key, [])
end

#same?(content) ⇒ 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.

Parameters:

  • content (Array<void>)

Returns:



44
45
46
# File 'lib/vedeu/output/compressor_cache.rb', line 44

def same?(content)
  content == read(:original)
end

#size?(content) ⇒ 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.

Parameters:

  • content (Array<void>)

Returns:



38
39
40
# File 'lib/vedeu/output/compressor_cache.rb', line 38

def size?(content)
  content.size == read(:original).size
end

#uncompress(content) ⇒ 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.

Parameters:

  • content (Array<void>)

Returns:

  • (String)


77
78
79
# File 'lib/vedeu/output/compressor_cache.rb', line 77

def uncompress(content)
  Vedeu::Output::Compressors::Simple.with(content)
end

#write(content, compression) ⇒ Hash<Symbol => Array<void>> (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.

Parameters:

  • content (Array<void>)
  • compression (Boolean)

Returns:

  • (Hash<Symbol => Array<void>>)


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/vedeu/output/compressor_cache.rb', line 84

def write(content, compression)
  storage[:original] = content

  if compression
    storage[:compress] = compress(content)

  else
    storage[:uncompress] = uncompress(content)

  end
end