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>)

Returns:

  • (String)


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

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



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

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)


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

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:



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

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>)


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

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>)


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

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:



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

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:



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

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)


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

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

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

Returns:

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


82
83
84
85
86
87
88
# File 'lib/vedeu/output/compressor_cache.rb', line 82

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

  storage[:uncompress] = uncompress(content)

  storage[:compress] = compress(content)
end