Class: CZTop::Z85::Pipe::Strategy Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/cztop/z85/pipe.rb

Overview

This class is abstract.

Different encoding/decoding strategies (algorithms).

This is mainly just for me to practice the GoF Strategy Pattern.

Direct Known Subclasses

Parallel, Sequential

Defined Under Namespace

Classes: Parallel, Sequential

Instance Method Summary collapse

Constructor Details

#initialize(source, sink, read_sz, &xcode) {|chunk, prev_chunk| ... } ⇒ Strategy

Returns a new instance of Strategy.

Parameters:

  • source (IO)

    the source

  • sink (IO)

    the sink

  • read_sz (Integer)

    chunk size when reading from source

  • xcode (Proc)

    block to encode or decode data

Yield Parameters:

  • chunk (String, nil)

    current chunk (or nil after the last one)

  • prev_chunk (String, nil)

    previous chunk (or nil for the first time)

Yield Returns:

  • (String)

    encoded/decoded chunk to write to sink



80
81
82
83
84
85
# File 'lib/cztop/z85/pipe.rb', line 80

def initialize(source, sink, read_sz, &xcode)
  @source  = source
  @sink    = sink
  @read_sz = read_sz
  @xcode   = xcode
end

Instance Method Details

#executeObject

This method is abstract.

Runs the algorithm.

Raises:

  • (void)


91
92
93
# File 'lib/cztop/z85/pipe.rb', line 91

def execute
  raise NotImplementedError
end