Sha256: 9f069cd647bd0d810a5d898221bb9d8bf40bbddeff8a4a6aaecc444c688effd8

Contents?: true

Size: 829 Bytes

Versions: 5

Compression:

Stored size: 829 Bytes

Contents

# -*- ruby -*-

require 'base64' # Ruby Standard Library

module Metadata
  module V2
    class Response
      def initialize(frame)
        @frame = frame
        self
      end

      attr_reader :frame

      def to_s
        frame + "\n"
      end

      def protocol
        @protocol ||= frame.split(' ')[0]
      end

      def length
        @length ||= frame.split(' ')[1].to_i
      end

      def checksum
        @checksum ||= frame.split(' ')[2]
      end

      def body
        @body ||= frame.split(' ').drop(3).join(' ')
      end

      def id
        @id ||= body.split(' ')[0]
      end

      def code
        @code ||= body.split(' ')[1]
      end

      def payload
        @payload ||= body.split(' ')[2]
      end

      def decode
        Base64.decode64 payload if payload
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
metadata-v2-0.8.12 lib/metadata/v2/response.rb
metadata-v2-0.8.11 lib/metadata/v2/response.rb
metadata-v2-0.8.10 lib/metadata/v2/response.rb
metadata-v2-0.8.9 lib/metadata/v2/response.rb
metadata-v2-0.8.5.pre lib/metadata/v2/response.rb