On 12 August 2010 05:33, Patrick Mohr <kc7...@gmail.com> wrote: > I'm making a provider for cups and I need to parse a string into arbitrary > key/value pairs. The string looks like this: > > printer-make-and-model='Brother HL-2060 Foomatic/hpijs-pcl5e (recommended)' > printer-state=3 printer-state-change-time=1266621145 > printer-state-reasons=none printer-type=8564756 > > I know almost no ruby. Any advice for what functions or data structures I > want to use? It looks like "split" might be what I want to use for parsing, > but the quoted strings will give me trouble. For the first version, I'm only > using 3 of the values. Do I just want to pull out those manually instead of > parsing the whole string?
You might use shellwords to handle the quoting. >> require 'shellwords' >> l = %q(printer-make-and-model='Brother HL-2060 Foomatic/hpijs-pcl5e >> (recommended)' printer-state=3 printer-state-change-time=1266621145 >> printer-state-reasons=none printer-type=8564756) >> Shellwords.shellwords(l) => ["printer-make-and-model=Brother HL-2060 Foomatic/hpijs-pcl5e (recommended)", "printer-state=3", "printer-state-change-time=1266621145", "printer-state-reasons=none", "printer-type=8564756"] Paul -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.