Class: KJess::Response::DumpedStats

Inherits:
KJess::Response show all
Defined in:
lib/kjess/response/dumped_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/dumped_stats.rb', line 6

def data
  @data
end

Instance Method Details

#convert_value(value) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/kjess/response/dumped_stats.rb', line 38

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
33
34
35
36
# File 'lib/kjess/response/dumped_stats.rb', line 13

def read_more( connection )
  queue_line_re = /\Aqueue\s+'(\S+)' \{\Z/
  stat_line_re  = /\A(\w+)=(\S+)\Z/
  stats         = Hash.new
  line          = message.strip
  current_queue = nil

  begin
    line.strip!
    if md = stat_line_re.match( line ) then
      stats[current_queue][md.captures[0]] = convert_value( md.captures[1] )
    elsif md = queue_line_re.match( line ) then
      current_queue = md.captures.first
      stats[current_queue] = Hash.new
    elsif line == "}" then
      current_queue = nil
    elsif line == "END" then
      break
    else
      # do nothing -- empty line
    end
  end while line = connection.readline
  @data = stats
end