Sha256: 6596f265950cd71da16c1247e80deaebae2aaf3505aa8d3a08dac45b485000dc

Contents?: true

Size: 656 Bytes

Versions: 4

Compression:

Stored size: 656 Bytes

Contents

require "delegate"

module Rmpd

  class MultiResponse < DelegateClass(Array)

    END_OF_RECORD = "\0x1E" # from ASCII

    def initialize(data, sep)
      super([])
      @sep = sep
      parse(data)
    end

    def ok?
      self.all?(&:ok?)
    end

    def ack?
      !ok?
    end

    def error
      self.map(&:error).compact.first
    end


    private

    def parse(data)
      data.gsub!(@sep, "#{END_OF_RECORD}\\1")
      data.split(END_OF_RECORD).each do |datum|
        if datum.empty?
          next
        else
          r = Response.new(datum)
        end
        self << r unless r.keys.size.zero? && r.ok?
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rmpd-1.0.5 lib/rmpd/multi_response.rb
rmpd-1.0.4 lib/rmpd/multi_response.rb
rmpd-1.0.3 lib/rmpd/multi_response.rb
rmpd-1.0.2 lib/rmpd/multi_response.rb