Class: KJess::Response::Stats

Inherits:
KJess::Response show all
Defined in:
lib/kjess/response/stats.rb

Constant Summary

Constants inherited from KJess::Response

Registry

Constants inherited from Protocol

Protocol::CRLF

Instance Attribute Summary collapse

Attributes inherited from Protocol

#args, #raw_args

Instance Method Summary collapse

Methods inherited from KJess::Response

#error?, #message, parse, #parse_options_to_args, registry

Methods inherited from Protocol

arity, #initialize, keyword, #keyword, #parse_options_to_args, register, #to_protocol

Constructor Details

This class inherits a constructor from KJess::Protocol

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/kjess/response/stats.rb', line 6

def data
  @data
end

Instance Method Details

#convert_key(key) ⇒ Object

Internal: conver the line from STATS to a valid key for the stats hash.

key - the under_scored key

returns the new key



39
40
41
42
43
# File 'lib/kjess/response/stats.rb', line 39

def convert_key( key )
  key_parts = key.split("_")
  return nil if key_parts.first == "queue" and key_parts.size > 2
  return key
end

#convert_value(value) ⇒ Object

Internal: convert the given value to the Integer, Float if it should be.

value - the item to convert

Returns a Float, Integer or the item itself



50
51
52
53
54
55
56
57
58
# File 'lib/kjess/response/stats.rb', line 50

def convert_value( value )
  if value =~ /\A\d+\Z/ then
    Float( value ).to_i
  elsif value =~ /\A\d+\.\d+\Z/
    Float( value )
  else
    value
  end
end

#read_more(connection) ⇒ Object

Internal: Read the extra data from the value

Read the datablock that is after the value and then the final END marker.

Returns nothing



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kjess/response/stats.rb', line 13

def read_more( connection )
  stats = Hash.new
  line  = message

  begin
    cmd, raw_key, raw_value = line.strip.split
    case cmd
    when "STAT"
      key        = convert_key( raw_key )
      value      = convert_value( raw_value )
      stats[key] = value
    when "END"
      break
    else
      raise KJess::ClientError, "Unknown line '#{line.strip}' from STAT command"
    end
  end while line = connection.readline

  @data = stats
end