Convert multiline string to hash

I have to test a custom cli. When I change a value using a command
inside cli I use “show” command to check expected values. The show
command output produces a multiline string where I can see different
name/value pairs.The output string is :

"

Status | Disabled
Alias | DP1
Chaddr | 11:22:33:44:55:66
Chaddr Exclude | false
Chaddr Mask | FF:FF:FF:FF:F8:00
Client ID |
Client ID Exclude | false
DHCP Server IP Address | 192.168.200.254
Locally Served | false
Order | 1
User Class ID |
User Class ID Exclude | false
Vendor Class ID |
Vendor Class ID Exclude | false
Vendor Class ID Mode | Exact
Interface in | br0
Interface out | eth4

dhcprpool1:

Enable | true
Status | Disabled
Alias | DP2
Chaddr | 11:22:33:44:55:66
Chaddr Exclude | false
Chaddr Mask | FF:FF:FF:FF:F8:00
Client ID |
Client ID Exclude | false
DHCP Server IP Address | 192.168.200.254
Locally Served | false
Order | 1
User Class ID |
User Class ID Exclude | false
Vendor Class ID |
Vendor Class ID Exclude | false
Vendor Class ID Mode | Exact
Interface in | br0
Interface out | eth4

"

n order to check if values are correct I would like build two hashes for
every item ( dhcprpool0 and dhcprpool1). I would like two hashes in
Ruby,i.e.:

dhcprpool0 = {“Enable” => “true”, “Status” => Disabled,“Alias”=>“DP1”
…}
dhcprpool1 = {“Enable” => “true”, “Status” => Disabled,
“Alias”=>“DP2”… }

How can I make it ?

Thanks

hi Robert K.,

you used

require ‘pp’
pp data

why are you using this pp instead of using p or puts? Is there any
specific reason for this?

data = {}
key = nil

ARGF.each_line do |line|
case line
when /^(\w+):$/
key = $1
when
/^\s*(.{0,26})\s*|\s+(.+?)\s*$/
raise “Format error” unless key
(data[key] ||= {})[$1] = $2
end
end

require ‘pp’
pp data

Raja gopalan wrote in post #1167516:

you used

require ‘pp’
pp data

why are you using this pp instead of using p or puts? Is there any
specific reason for this?

Try it out and see the difference.

hi

I tried with these two ways,

class Raj
def h
puts ‘hi’
end
end

o=Raj.new
p o
require ‘pp’
pp o

a=‘Raj’
p a
pp a

But output is same

#Raj:0x2793300
#Raj:0x2793300
“Raj”
“Raj”

That’s what I have raised a question.