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.

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:

  • content (Array<void>)


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

def initialize(content)
  @content = content
  @colour  = ''
  @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.



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

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:

  • content (Array<void>)

Returns:

  • (String)


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

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

Instance Method Details

#colour_for(char) ⇒ String (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.

Compress by not repeatedly sending the same colours for each character which has the same colours as the last character output.

Parameters:

Returns:

  • (String)


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

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

  @colour = char.colour
  @colour.to_s
end

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

  • (String)


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

def message
  "Compression for #{original_size} objects"
end

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

  • (Fixnum)


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

def original_size
  content.size
end

#style_for(char) ⇒ String (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.

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:

  • (String)


92
93
94
95
96
97
# File 'lib/vedeu/output/compressors/character.rb', line 92

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

  @style = char.style
  @style.to_s
end

#withString

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:

  • (String)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vedeu/output/compressors/character.rb', line 31

def with
  @same = ''
  @compress ||= Vedeu.timer(message) do
    content.map do |cell|
      rendered = [
        cell.position.to_s,
        colour_for(cell),
        style_for(cell),
        cell.value,
      ].join

      if @same == rendered
        next

      else
        @same = rendered
        @same

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