Class: KJess::Response::Stats
- Inherits:
-
KJess::Response
- Object
- Protocol
- KJess::Response
- KJess::Response::Stats
- Defined in:
- lib/kjess/response/stats.rb
Constant Summary
Constants inherited from KJess::Response
Constants inherited from Protocol
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Attributes inherited from Protocol
Instance Method Summary collapse
-
#convert_key(key) ⇒ Object
Internal: conver the line from STATS to a valid key for the stats hash.
-
#convert_value(value) ⇒ Object
Internal: convert the given value to the Integer, Float if it should be.
-
#read_more(connection) ⇒ Object
Internal: Read the extra data from the value.
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
#data ⇒ Object
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 = 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 |