I have decided to migrate a small package managing program I was developing in ruby over to crystal for performance reasons, and I’m having some hiccups with the yaml/json libs.
My program takes a search query and pulls down results from and http rpc interface. The results are in JSON, however I would much rather use YAML because it makes my life easier reading-wise. I have the functionality of parsing the results into YAML, and being able to write them to a file or stdout, but I’m stuggling to get it to a point where the yaml is formatted the way I’d like it to be.
---
- Description: A CLI system information tool written in BASH that supports displaying images.
Name: neofetch-git
URL: https://github.com/dylanaraps/neofetch
URLPath: /cgit/aur.git/snapshot/neofetch-git.tar.gz
Version: 3.2.0.r28.g2eca41d-1
- Description: some other package xyz
Name: packagename
this is an example of the output im working with.
I used a YAML::Serialization class to format them a bit differently, like such
---
Name: neofetch-git
Description: A CLI system information tool written in BASH that supports displaying
images.
Version: 3.2.0.r28.g2eca41d-1
URLPath: /cgit/aur.git/snapshot/neofetch-git.tar.gz
NumVotes: 30
URL: https://github.com/dylanaraps/neofetch
---
But i am unable to read multiple entries of this from a file, it will only see the first one and then exit, I imagine it is because of the — on the beginning and end of the entry.
what i want my results to be is something along the lines of this…
---
- Package: packagename1
PkgInfo: ["Name": name, "Version": version, "Description": desc, # so on & so forth ]
- Package: packagename2
PkgInfo: ["Name": name, "Version": version, "Description": desc, # so on & so forth ]
- Package: packagename3
PkgInfo: ["Name": name, "Version": version, "Description": desc, # so on & so forth ]
I know that this is a hash that I am trying to make, but it seems the YAML objects have very few methods, or perhaps I am just using the wrong ones to be able to easily access those values programmatically. I know this has been a long question, but i assume if anyone is going to read through a post this long about yaml formatting and access, that they probably see a decent amount of value in it being readable/elegant and accessible. If anyone has any ideas or can point me in the direction of something that may help me I would really appreciate it. Thank you for coming to my TED talk.