Class: Jubatus::Common::MessageStringGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/jubatus/common/message_string_generator.rb

Constant Summary collapse

OPEN =
"{"
COLON =
": "
DELIMITER =
", "
CLOSE =
"}"

Instance Method Summary collapse

Constructor Details

#initializeMessageStringGenerator

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

#closeObject



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_sObject



35
36
37
# File 'lib/jubatus/common/message_string_generator.rb', line 35

def to_s
  @buf.join
end