Class: QuantifiableStdout

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb

Overview

A delegator that allows the size method to be used on the STDOUT object.

The size of the content written to STDOUT cannot be measured normally. This class wraps the STDOUT object so the cumulative size of the content passed to the write method (while wrapped in this decorator) can be measured.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate) ⇒ QuantifiableStdout

Returns a new instance of QuantifiableStdout.



13
14
15
16
17
# File 'lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb', line 13

def initialize delegate
  @size = 0
  super
  delegate.binmode
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



11
12
13
# File 'lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb', line 11

def size
  @size
end

Instance Method Details

#<<(content) ⇒ Object Also known as: write



19
20
21
22
# File 'lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb', line 19

def << content
  @size += content.to_s.bytesize
  super
end