Class: Baykit::BayServer::Util::KeyValListParser

Inherits:
Object
  • Object
show all
Defined in:
lib/baykit/bayserver/util/key_val_list_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_sep = "&", key_val_sep = "=") ⇒ KeyValListParser



11
12
13
14
# File 'lib/baykit/bayserver/util/key_val_list_parser.rb', line 11

def initialize(item_sep = "&", key_val_sep = "=")
  @item_sep = item_sep
  @kv_sep = key_val_sep
end

Instance Attribute Details

#item_sepObject (readonly)

Returns the value of attribute item_sep.



8
9
10
# File 'lib/baykit/bayserver/util/key_val_list_parser.rb', line 8

def item_sep
  @item_sep
end

#kv_sepObject (readonly)

Returns the value of attribute kv_sep.



9
10
11
# File 'lib/baykit/bayserver/util/key_val_list_parser.rb', line 9

def kv_sep
  @kv_sep
end

Instance Method Details

#parse(str) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/baykit/bayserver/util/key_val_list_parser.rb', line 16

def parse(str)
  list = []
  buf = ""
  str.each do |c|
    if(c == @item_sep)
      list.append(divide_param(buf))
      buf.clear()
    else
      buf.concat(c)
    end
  end
  if(buf.length > 0)
    list.append(divide_param(buf))
  end

  return list
end