class IOP::StringSplitter
Feed
class to send arbitrary string in blocks of specified size.
### Use case: split the string into 3-byte blocks and reconstruct it.
require 'iop/string' ( IOP::StringSplitter.new('Hello IOP', 3) | IOP::StringMerger.new ).process!
@since 0.1
Public Class Methods
new(string, block_size: DEFAULT_BLOCK_SIZE)
click to toggle source
Creates class instance.
@param string [String] string to be sent in blocks
@param block_size [Integer] size of block the string is split into
# File lib/iop/string.rb, line 26 def initialize(string, block_size: DEFAULT_BLOCK_SIZE) @string = string @block_size = block_size end
Public Instance Methods
process!()
click to toggle source
# File lib/iop/string.rb, line 31 def process! offset = 0 (0..@string.size / @block_size - 1).each do process(@string[offset, @block_size]) offset += @block_size end process(offset.zero? ? @string : @string[offset..-1]) unless offset == @string.size process end