Class: Vedeu::Output::Compressors::Character Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/output/compressors/character.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.

A simple character based compressor which compressed based on the previous character’s attributes.

API:

  • private

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Vedeu::Output::Compressors::Character

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:

API:

  • private



24
25
26
27
28
29
# File 'lib/vedeu/output/compressors/character.rb', line 24

def initialize(content)
  @content = content
  @colour  = ''
  @same    = ''
  @style   = ''
end

Instance Attribute Details

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

This method returns an undefined value.

API:

  • private



52
53
54
# File 'lib/vedeu/output/compressors/character.rb', line 52

def content
  @content
end

Class Method Details

.with(content) ⇒ 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:

API:

  • private



18
19
20
# File 'lib/vedeu/output/compressors/character.rb', line 18

def self.with(content)
  new(content).compress
end

Instance Method Details

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

Parameters:

Returns:

API:

  • private



58
59
60
61
62
63
# File 'lib/vedeu/output/compressors/character.rb', line 58

def character_for(char)
  position_for(char) +
    colour_for(char) +
    style_for(char) +
    value_for(char)
end

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

Parameters:

Returns:

API:

  • private



71
72
73
74
75
76
# File 'lib/vedeu/output/compressors/character.rb', line 71

def colour_for(char)
  return '' if char.colour == @colour

  @colour = char.colour
  @colour.to_s
end

#compressString

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.

Process the content as a stream; for each sequence with the same position take the first sequence and ignore the rest.

Returns:

API:

  • private



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vedeu/output/compressors/character.rb', line 35

def compress
  Vedeu.timer('Removing duplicate cells...') do
    content.map do |cell|
      character = character_for(cell)

      character == @same ? next : @same = character
    end.join.tap do |out|
      Vedeu.log(type:    :compress,
                message: "#{message} -> #{out.size} characters")
    end
  end
end

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

API:

  • private



79
80
81
# File 'lib/vedeu/output/compressors/character.rb', line 79

def message
  "Compression for #{content.size} objects"
end

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

Parameters:

Returns:

API:

  • private



85
86
87
88
89
# File 'lib/vedeu/output/compressors/character.rb', line 85

def position_for(char)
  return '' unless char.position?

  char.position.to_s
end

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

Parameters:

Returns:

API:

  • private



97
98
99
100
101
102
# File 'lib/vedeu/output/compressors/character.rb', line 97

def style_for(char)
  return '' if char.style == @style

  @style = char.style
  @style.to_s
end

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

Parameters:

Returns:

API:

  • private



106
107
108
109
110
# File 'lib/vedeu/output/compressors/character.rb', line 106

def value_for(char)
  return '' unless char.value?

  char.value
end