Class: HexaPDF::FiberDoubleForString

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/filter.rb

Overview

Implements part of the Fiber interface so that it can be used instead of a Fiber by HexaPDF when only a single string should be returned.

Instance Method Summary collapse

Constructor Details

#initialize(str = nil, &block) ⇒ FiberDoubleForString

Creates a new FiberDoubleForString instance for the given string str or for the string returned by invoking the block.



66
67
68
69
70
# File 'lib/hexapdf/filter.rb', line 66

def initialize(str = nil, &block)
  @block = block
  @str = str
  @block_used = false
end

Instance Method Details

#alive?Boolean

Returns true if #resume has not yet been called.

Returns:

  • (Boolean)


80
81
82
# File 'lib/hexapdf/filter.rb', line 80

def alive?
  !str.nil?
end

#lengthObject

Returns the length in bytes of the wrapped string.

May only be called before #resume!



75
76
77
# File 'lib/hexapdf/filter.rb', line 75

def length
  str.bytesize
end

#resumeObject

Returns the wrapped string on the first invocation, nil otherwise.



85
86
87
88
89
# File 'lib/hexapdf/filter.rb', line 85

def resume
  tmp = str
  @str = nil
  tmp
end