Module: Rubyplat::Utils::Parser

Included in:
Responses::Response
Defined in:
lib/rubyplat/utils/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(response_body) ⇒ Hash

Returns hash of key value hashes.

Parameters:

  • response_body (String)

    response from cyberplat api

Returns:

  • (Hash)

    hash of key value hashes



7
8
9
10
11
12
13
14
15
16
# File 'lib/rubyplat/utils/parser.rb', line 7

def parse(response_body)
  regex = /BEGIN\r\n(.*)END\r\n/m
  body = response_body.match(regex)[1].scan(/(?<key>.*)=(?<value>.*)\r\n/)
  params = {}
  body.each do |param|
    k,v = param
    params[k.strip.downcase.to_sym] = v
  end
  params
end