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



34
35
36
37
38
39
40
# File 'lib/sanford-protocol/response.rb', line 34

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

#inspectObject



29
30
31
32
# File 'lib/sanford-protocol/response.rb', line 29

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

#to_hashObject



23
24
25
26
27
# File 'lib/sanford-protocol/response.rb', line 23

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

#to_sObject



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

def to_s; status.to_s; end