Ruby parse yaml files




















For information on using the high level parser see Psych. The high level emitter has the easiest interface. See Psych. The AST can be examined and manipulated freely. At the mid level is building an AST. The lowest level parser should be used when the YAML input is already known, and the developer does not want to pay the price of building an AST or automatic detection and conversion to Ruby objects. See Psych::Parser for more information on using the event based parser.

The lowest level emitter is an event based system. Events are sent to a Psych::Emitter object. That object knows how to convert the events to a YAML document. This interface should be used when document format is known in advance or speed is a concern.

See Psych::Emitter for more information. Optional options may be passed in to control the output format. Number of space characters used to indent. I need to pull in some YAML as bash variables.

The YAML will never be more than one level deep. How can I check if a directory exists in a Bash shell script? How to check if a string contains a substring in Bash. Dmitriy Vinokurov 1 1 gold badge 4 4 silver badges 22 22 bronze badges. Yeah, the file does exist and is in the right location. Ive updated my post with the error.

Add a comment. Active Oldest Votes. If your sample YAML is in some. Improve this answer. Nathan Mike Woodhouse Mike Woodhouse I agree, that's the wonderful about YAML - we can serialize something then read it back in later, so why not use that capability.

Thanks so much! Huh, it was because I was using tabs. It seems that it only wants spaces instead of tabs, and then throws all sorts of errors. I found this solution in this Stack Overflow answer , and other answers in that thread had some interesting ways of doing it natively in bash without requiring a language interpreter present on the server, like Ruby, PHP, or Python.

But using a library like Ruby's yaml library means a lot of weird edge cases are covered that might trip up a custom YAML interpreter! This is great, thank you for sharing.



0コメント

  • 1000 / 1000