<commit_before>require 'strscan'

module LIS::Transfer

  # a chainable IO-Listener that provides to methods:
  #
  # +on_data+ :: a callback that is called whenever a message is received
  # +write+   :: can be called so send messages to the underlying IO
  #
  # when overriding this class, you need to implement two methods:
  #
  # +receive+ :: is called from an underlying IO whenever a message is received
  #              the message can be handled, if messages should be propagated, you
  #              need to call `forward`
  #
  # +write+ :: when data needs to be encoded, formatted before it can be send
  #            send it with `super`
  #
  #
  class Base
    def initialize(read, write = read)
      @reader, @writer = read, write
      @on_data = nil
      @reader.on_data { |*data| receive(*data) } if @reader.respond_to?(:on_data)
    end

    def on_data(&block)
      @on_data = block
    end

    def write(message)
      @writer << message if @writer
    end<commit_msg>handle write with multiple arguments correctly<commit_after>require 'strscan'

module LIS::Transfer

  # a chainable IO-Listener that provides to methods:
  #
  # +on_data+ :: a callback that is called whenever a message is received
  # +write+   :: can be called so send messages to the underlying IO
  #
  # when overriding this class, you need to implement two methods:
  #
  # +receive+ :: is called from an underlying IO whenever a message is received
  #              the message can be handled, if messages should be propagated, you
  #              need to call `forward`
  #
  # +write+ :: when data needs to be encoded, formatted before it can be send
  #            send it with `super`
  #
  #
  class Base
    def initialize(read, write = read)
      @reader, @writer = read, write
      @on_data = nil
      @reader.on_data { |*data| receive(*data) } if @reader.respond_to?(:on_data)
    end

    def on_data(&block)
      @on_data = block
    end

    def write(*args)
      @writer.<<(*args) if @writer
    end
{'fraction_non_alphanumeric': 0.08852621167161226, 'fraction_numerical': 0.0, 'mean_word_length': 2.6582278481012658, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5794275', 'n_tokens_mistral': 597, 'n_tokens_neox': 580, 'n_words': 237}