Class: Jubatus::Common::MessageStringGenerator
- Inherits:
-
Object
- Object
- Jubatus::Common::MessageStringGenerator
- Defined in:
- lib/jubatus/common/message_string_generator.rb
Constant Summary collapse
- OPEN =
"{"
- COLON =
": "
- DELIMITER =
", "
- CLOSE =
"}"
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #close ⇒ Object
-
#initialize ⇒ MessageStringGenerator
constructor
A new instance of MessageStringGenerator.
- #open(typ) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ MessageStringGenerator
Returns a new instance of MessageStringGenerator.
10 11 12 13 |
# File 'lib/jubatus/common/message_string_generator.rb', line 10 def initialize() @buf = [] @first = true end |
Instance Method Details
#add(key, value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jubatus/common/message_string_generator.rb', line 20 def add(key, value) if @first @first = false else @buf << DELIMITER end @buf << key.to_s @buf << COLON @buf << value.to_s end |
#close ⇒ Object
31 32 33 |
# File 'lib/jubatus/common/message_string_generator.rb', line 31 def close @buf << CLOSE end |
#open(typ) ⇒ Object
15 16 17 18 |
# File 'lib/jubatus/common/message_string_generator.rb', line 15 def open(typ) @buf << typ.to_s @buf << OPEN end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/jubatus/common/message_string_generator.rb', line 35 def to_s @buf.join end |