Hi i have a yaml file like so
---
data:
- date: "2004-06-11"
description: First description
- date: "2008-01-12"
description: Another descripion
How can i do a "ypath" query similar to xpath for xml ? Something like "get the description where the date is 2004-06-11"
YAML.parse_file('myfile.yml').select('/data/*/date == 2004-06-11')
How do you do it, and if that's possible how can i similarly edit the description by 'ypath' ?
Thanks
There is indeed such thing as YPath: github.com/peterkmurphy/YPath-Specification
And it's implemented in Ruby's YAML lib; see the doc for BaseNode#search.
If Ruby is not a hard constraint you might take a look at the dpath tool. It provides an xpath-like query language to YAML (and other) files. Maybe call it externally to filter your data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With