Class: Vedeu::Output::Compressors::Character Private
- Inherits:
-
Object
- Object
- Vedeu::Output::Compressors::Character
- 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
- #content ⇒ void readonly protected private
Class Method Summary collapse
- .with(content) ⇒ String private
Instance Method Summary collapse
-
#colour_for(char) ⇒ String
private
private
Compress by not repeatedly sending the same colours for each character which has the same colours as the last character output.
- #initialize(content) ⇒ Vedeu::Output::Compressors::Character constructor private
- #message ⇒ String private private
- #original_size ⇒ Fixnum private private
- #position_for(char) ⇒ String private private
-
#style_for(char) ⇒ String
private
private
Compress by not repeatedly sending the same style(s) for each character which has the same style(s) as the last character output.
- #value_for(char) ⇒ String private private
-
#with ⇒ String
private
Process the content as a stream; for each sequence with the same position take the first sequence and ignore the rest.
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.
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
#content ⇒ void (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.
57 58 59 |
# File 'lib/vedeu/output/compressors/character.rb', line 57 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.
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 (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.
67 68 69 70 71 72 |
# File 'lib/vedeu/output/compressors/character.rb', line 67 def colour_for(char) return '' if char.colour == @colour @colour = char.colour @colour.to_s end |
#message ⇒ 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.
75 76 77 |
# File 'lib/vedeu/output/compressors/character.rb', line 75 def "Compression for #{original_size} objects" end |
#original_size ⇒ Fixnum (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.
80 81 82 |
# File 'lib/vedeu/output/compressors/character.rb', line 80 def original_size content.size 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.
86 87 88 89 90 |
# File 'lib/vedeu/output/compressors/character.rb', line 86 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.
98 99 100 101 102 103 |
# File 'lib/vedeu/output/compressors/character.rb', line 98 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.
107 108 109 110 111 |
# File 'lib/vedeu/output/compressors/character.rb', line 107 def value_for(char) return '' unless char.value? char.value end |
#with ⇒ 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.
Process the content as a stream; for each sequence with the same position take the first sequence and ignore the rest.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vedeu/output/compressors/character.rb', line 34 def with @same = '' @compress ||= Vedeu.timer() do content.map do |cell| character = [ position_for(cell), colour_for(cell), style_for(cell), value_for(cell), ].join character == @same ? next : @same = character end.join.tap do |out| Vedeu.log(type: :compress, message: "#{message} -> #{out.size} characters") end end end |