Class: Sanford::Protocol::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/sanford-protocol/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, data = nil) ⇒ Response

Returns a new instance of Response.



16
17
18
# File 'lib/sanford-protocol/response.rb', line 16

def initialize(status, data = nil)
  super(build_status(status), data)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



10
11
12
# File 'lib/sanford-protocol/response.rb', line 10

def data
  @data
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



10
11
12
# File 'lib/sanford-protocol/response.rb', line 10

def status
  @status
end

Class Method Details

.parse(hash) ⇒ Object



12
13
14
# File 'lib/sanford-protocol/response.rb', line 12

def self.parse(hash)
  self.new(hash['status'], hash['data'])
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/sanford-protocol/response.rb', line 37

def ==(other)
  if other.kind_of?(self.class)
    self.to_hash == other.to_hash
  else
    super
  end
end

#codeObject



20
# File 'lib/sanford-protocol/response.rb', line 20

def code;            status.code;            end

#code=(value) ⇒ Object



21
# File 'lib/sanford-protocol/response.rb', line 21

def code=(value);    status.code = value;    end

#inspectObject



32
33
34
35
# File 'lib/sanford-protocol/response.rb', line 32

def inspect
  reference = '0x0%x' % (self.object_id << 1)
  "#<#{self.class}:#{reference} @status=#{status} @data=#{data.inspect}>"
end

#messageObject



22
# File 'lib/sanford-protocol/response.rb', line 22

def message;         status.message;         end

#message=(value) ⇒ Object



23
# File 'lib/sanford-protocol/response.rb', line 23

def message=(value); status.message = value; end

#to_hashObject



26
27
28
29
30
# File 'lib/sanford-protocol/response.rb', line 26

def to_hash
  { 'status' => [status.code, status.message],
    'data'   => data
  }
end

#to_sObject



24
# File 'lib/sanford-protocol/response.rb', line 24

def to_s;            status.to_s;            end