Sha256: 75d0478862127c72fe7647a0362196c90b567616a4b558838250202a1a9c2d4e

Contents?: true

Size: 642 Bytes

Versions: 11

Compression:

Stored size: 642 Bytes

Contents

# frozen_string_literal: true

require 'delegate'

# 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.
class QuantifiableStdout < SimpleDelegator
  attr_reader :size

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

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.6.2 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.6.1 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.6.0 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.4 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.3 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.2 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.1 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.0 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.0.rc.3 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.0.rc.2 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb
asciidoctor-pdf-1.5.0.rc.1 lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb