Sha256: b3defc42b3cb91d0277f1a40defbcd2dab3875d63337e290502e19a3df45843f

Contents?: true

Size: 658 Bytes

Versions: 2

Compression:

Stored size: 658 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? {|x| x.ok?}
    end

    def ack?
      !ok?
    end

    def error
      self.find(nil) {|x| x.error}
    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

2 entries across 2 versions & 1 rubygems

Version Path
rmpd-1.0.1 lib/rmpd/multi_response.rb
rmpd-1.0.0 lib/rmpd/multi_response.rb